Exemplo n.º 1
0
func (h *TenantHandler) AddUsersToTenant(TenantID, Name string, users, SecurityLevel string) TenantUsers {
	bytes, err := client.Go("ignore", "com.duosoftware.tenant", "users").GetOne().ByUniqueKey(TenantID).Ok()
	var t TenantUsers
	if err == "" {
		err := json.Unmarshal(bytes, &t)
		if err != nil {
			term.Write("No Users yet assigied "+t.TenantID, term.Debug)
			//t=TenantUsers{}
			t = TenantUsers{TenantID, []string{}}
			t.TenantID = TenantID
		} else {
			for _, element := range t.Users {
				if element == users {
					return t
				}
			}
		}
		h.AddTenantForUsers(TenantMinimum{TenantID, Name}, users)
		t.Users = append(t.Users, users)
		var Activ TenantAutherized
		Activ = TenantAutherized{}
		id := common.GetHash(users + "-" + TenantID)
		Activ.Autherized = true
		Activ.ID = id
		Activ.TenantID = TenantID
		Activ.SecurityLevel = SecurityLevel
		Activ.UserID = users
		client.Go("ignore", "com.duosoftware.tenant", "authorized").StoreObject().WithKeyField("ID").AndStoreOne(Activ).Ok()
		client.Go("ignore", "com.duosoftware.tenant", "users").StoreObject().WithKeyField("TenantID").AndStoreOne(t).Ok()
		term.Write("Saved Tenant users"+t.TenantID, term.Debug)
		return t
	} else {
		return t
	}
}
Exemplo n.º 2
0
func (h *TenantHandler) CreateTenant(t Tenant, user session.AuthCertificate, update bool) Tenant {
	term.Write("CreateTenant saving user  "+t.Name, term.Debug)
	//client.c
	bytes, err := client.Go("ignore", "com.duosoftware.tenant", "tenants").GetOne().ByUniqueKey(t.TenantID).Ok()
	if err == "" {
		var uList Tenant
		err := json.Unmarshal(bytes, &uList)
		if err != nil {
			if t.TenantID == "" {
				t.TenantID = common.GetGUID()
				term.Write("Auto Gen TID  "+t.TenantID+" New Tenant "+t.Name, term.Debug)
			}
			term.Write("Save Tenant saving Tenant  "+t.Name+" New Tenant "+t.Name, term.Debug)
			var inputParams map[string]string
			inputParams = make(map[string]string)
			inputParams["email"] = user.Email
			inputParams["name"] = user.Name
			inputParams["tenantID"] = t.TenantID
			inputParams["tenantName"] = t.Name
			h.AddUsersToTenant(t.TenantID, t.Name, user.UserID, "admin")

			email.Send("ignore", "com.duosoftware.auth", "tenant", "tenant_creation", inputParams, user.Email)
			client.Go("ignore", "com.duosoftware.tenant", "tenants").StoreObject().WithKeyField("TenantID").AndStoreOne(t).Ok()
		} else {
			if update {
				term.Write("SaveUser saving Tenant  "+t.TenantID+" Update user "+user.UserID, term.Debug)
				client.Go("ignore", "com.duosoftware.tenant", "tenants").StoreObject().WithKeyField("TenantID").AndStoreOne(t).Ok()
			}
		}
	} else {
		term.Write("SaveUser saving Tenant fetech Error #"+err, term.Error)
	}
	return t
}
Exemplo n.º 3
0
func (h *AuthHandler) AutherizeApp(Code, ApplicationID, AppSecret, UserID string) (bool, string) {
	bytes, err := client.Go("ignore", "com.duosoftware.auth", "authcode").GetOne().ByUniqueKey(Code).Ok()
	term.Write("AutherizeApp For ApplicationID "+ApplicationID+" Code "+Code+" Secret "+AppSecret+" Err "+err, term.Debug)
	var uList AuthCode
	err1 := json.Unmarshal(bytes, &uList)
	term.Write(string(bytes[:]), term.Debug)
	if err1 != nil {

		var appH applib.Apphanler
		application, err := appH.Get(ApplicationID, "ignorelib")
		if err == "" {
			if application.SecretKey == AppSecret && uList.UserID == UserID && Code == uList.Code {
				var appAth AppAutherize
				appAth.AppliccatioID = ApplicationID
				appAth.AutherizeKey = ApplicationID + "-" + UserID
				appAth.Name = application.Name

				client.Go("ignore", "com.duosoftware.auth", "atherized").StoreObject().WithKeyField("AutherizeKey").AndStoreOne(appAth).Ok()

				return true, ""
			}
		} else {
			return false, err
		}
	} else {
		return false, "Code invalid"
	}
	return false, "process error"

}
Exemplo n.º 4
0
func (h *TenantHandler) AddTenantForUsers(Tenant TenantMinimum, UserID string) UserTenants {
	bytes, err := client.Go("ignore", "com.duosoftware.tenant", "userstenantmappings").GetOne().ByUniqueKey(UserID).Ok()
	var t UserTenants
	//t.UserID
	if err == "" {
		err := json.Unmarshal(bytes, &t)
		if err != nil {
			term.Write("No Users yet assigied "+UserID, term.Debug)
			t = UserTenants{UserID, []TenantMinimum{}}
			t.UserID = UserID
		} else {
			for _, element := range t.TenantIDs {
				if element.TenantID == Tenant.TenantID {
					return t
				}
			}
		}
		t.TenantIDs = append(t.TenantIDs, Tenant)
		client.Go("ignore", "com.duosoftware.tenant", "userstenantmappings").StoreObject().WithKeyField("UserID").AndStoreOne(t).Ok()
		term.Write("Saved Tenant users"+UserID, term.Debug)
		return t
	} else {
		return t
	}
}
Exemplo n.º 5
0
func (h *AuthHandler) SaveUser(u User, update bool) User {
	term.Write("SaveUser saving user  "+u.Name, term.Debug)

	bytes, err := client.Go("ignore", "com.duosoftware.auth", "users").GetOne().ByUniqueKey(u.EmailAddress).Ok()
	if err == "" {
		var uList User
		err := json.Unmarshal(bytes, &uList)
		//if err == nil || bytes == nil {
		if err != nil {
			u.Active = false
			u.UserID = common.GetGUID()
			term.Write("SaveUser saving user  "+u.Name+" New User "+u.UserID, term.Debug)
			password := u.Password
			u.Password = common.GetHash(u.Password)
			u.ConfirmPassword = common.GetHash(u.ConfirmPassword)
			var Activ ActivationEmail
			Activ.GUUserID = u.EmailAddress
			Activ.Token = common.RandText(10)
			var inputParams map[string]string
			inputParams = make(map[string]string)
			inputParams["email"] = u.EmailAddress
			inputParams["name"] = u.Name
			inputParams["token"] = Activ.Token
			inputParams["password"] = password
			email.Send("ignore", "com.duosoftware.auth", "email", "user_activate", inputParams, u.EmailAddress)
			term.Write("E Mail Sent", term.Debug)
			client.Go("ignore", "com.duosoftware.auth", "activation").StoreObject().WithKeyField("Token").AndStoreOne(Activ).Ok()
			term.Write("Activation stored", term.Debug)
			client.Go("ignore", "com.duosoftware.auth", "users").StoreObject().WithKeyField("EmailAddress").AndStoreOne(u).Ok()
		} else {
			if update {
				u.UserID = uList.UserID
				u.Password = common.GetHash(u.Password)
				u.ConfirmPassword = common.GetHash(u.Password)
				term.Write("SaveUser saving user  "+u.Name+" Update User "+u.UserID, term.Debug)
				client.Go("ignore", "com.duosoftware.auth", "users").StoreObject().WithKeyField("EmailAddress").AndStoreOne(u).Ok()
			}
		}
		//} else {
		//term.Write("SaveUser saving user store Error #"+err.Error(), term.Error)
		//}
	} else {
		term.Write("SaveUser saving user fetech Error #"+err, term.Error)
	}
	u.Password = "******"
	u.ConfirmPassword = "******"
	return u
}
Exemplo n.º 6
0
func (h *AuthHandler) Login(email, password string) (User, string) {
	term.Write("Login  user  email"+email, term.Debug)
	term.Write(Config.UserName, term.Debug)

	bytes, err := client.Go("ignore", "com.duosoftware.auth", "users").GetOne().ByUniqueKey(email).Ok()
	var user User
	if err == "" {
		if bytes != nil {
			var uList User
			err := json.Unmarshal(bytes, &uList)
			if err == nil {
				if uList.Password == common.GetHash(password) && strings.ToLower(uList.EmailAddress) == strings.ToLower(email) {
					return uList, ""
				} else {
					term.Write("password incorrect", term.Error)
				}
			} else {
				if err != nil {
					term.Write("Login  user Error "+err.Error(), term.Error)
				}
			}
		}
	} else {
		term.Write("Login  user  Error "+err, term.Error)
	}

	return user, "Error Validating user"
}
Exemplo n.º 7
0
func GetSession(key, Domain string) (AuthCertificate, string) {
	bytes, err := client.Go(key, "s.duosoftware.auth", "sessions").GetOne().ByUniqueKey(key).Ok()
	term.Write("GetSession For SecurityToken "+key, term.Debug)
	//term.Write("GetSession For SecurityToken "+string(bytes), term.Debug)

	var c AuthCertificate
	if err == "" {
		if bytes != nil {
			var uList AuthCertificate
			err := json.Unmarshal(bytes, &uList)
			if err == nil {
				if Domain == "Nil" {
					return uList, ""
				} else {
					if strings.ToLower(uList.Domain) != strings.ToLower(Domain) {
						uList.Domain = strings.ToLower(Domain)
						uList.SecurityToken = common.GetGUID()
						AddSession(uList)
						return uList, ""
					} else {
						return uList, ""
					}
				}

			} else {
				term.Write("GetSession Error "+err.Error(), term.Error)
			}
		}
	} else {
		term.Write("GetSession Error "+err, term.Error)
	}
	term.Write("GetSession No Session for SecurityToken "+key, term.Debug)

	return c, "Error Session Not Found"
}
Exemplo n.º 8
0
func (f *FileManager) Remove(request *messaging.FileRequest) messaging.FileResponse { // remove file from disk and database
	fileResponse := messaging.FileResponse{}
	var saveServerPath string = request.RootSavePath
	file, err := ioutil.ReadFile(saveServerPath + request.FilePath + request.FileName)

	if len(file) > 0 {
		err = os.Remove(saveServerPath + request.FilePath + request.FileName)
	}

	if err == nil {
		fileResponse.IsSuccess = true
		fileResponse.Message = "Deletion of file successfully completed"
	} else {
		fileResponse.IsSuccess = true
		fileResponse.Message = "Deletion of file Aborted"
	}

	obj := FileData{}
	obj.Id = request.Parameters["id"]
	obj.FileName = request.FileName

	client.Go("token", request.Parameters["namespace"], request.Parameters["class"]).StoreObjectWithOperation("delete").WithKeyField("Id").AndStoreOne(obj).Ok()
	fileResponse.IsSuccess = true
	fileResponse.Message = "Deletion of file successfully completed"

	return fileResponse
}
Exemplo n.º 9
0
func (h *TenantHandler) AddUserToTenant(u session.AuthCertificate, users []InviteUsers) {
	for _, user := range users {
		var inputParams map[string]string
		inputParams = make(map[string]string)
		inputParams["email"] = user.Email
		inputParams["name"] = user.Name
		inputParams["userID"] = user.UserID
		inputParams["tenantID"] = u.Domain
		inputParams["FromName"] = u.Username
		inputParams["FromID"] = u.UserID
		inputParams["FromEmail"] = u.Email
		req := InviteUserRequest{}
		req.UserID = user.UserID
		req.TenantID = u.Domain
		req.RequestToken = common.RandText(10)
		req.Name = user.Name
		req.FromUserID = u.UserID
		req.FromName = u.Name
		req.FromEmail = u.Email
		req.Email = user.Email
		req.SecurityLevel = user.SecurityLevel

		//h.AddUsersToTenant(t.TenantID, user.UserID, "admin")
		client.Go("ignore", "com.duosoftware.tenant", "userrequest").StoreObject().WithKeyField("RequestToken").AndStoreOne(req).Ok()
		email.Send("ignore", "com.duosoftware.auth", "tenant", "tenant_request", inputParams, user.Email)
	}
}
Exemplo n.º 10
0
func (h *AuthHandler) GetUser(email string) (User, string) {
	term.Write("Login  user  email"+email, term.Debug)
	term.Write(Config.UserName, term.Debug)

	bytes, err := client.Go("ignore", "com.duosoftware.auth", "users").GetOne().ByUniqueKey(email).Ok()
	var user User
	if err == "" {
		if bytes != nil {
			var uList User
			err := json.Unmarshal(bytes, &uList)
			if err == nil {
				uList.Password = "******"
				uList.ConfirmPassword = "******"
				return uList, ""
			} else {
				if err != nil {
					term.Write("Login  user Error "+err.Error(), term.Error)
				}
			}
		}
	} else {
		term.Write("Login  user  Error "+err, term.Error)
	}

	return user, "Error Validating user"
}
Exemplo n.º 11
0
func handleRequest(params martini.Params, res http.ResponseWriter, req *http.Request) { // res and req are injected by Martini

	//start RabbitMQ Pusher

	fmt.Println(params)

	var requestBody1 messaging.ServiceRequest

	rb, _ := ioutil.ReadAll(req.Body)

	err := json.Unmarshal(rb, &requestBody1)

	if err != nil {
		fmt.Println("Error decoding from Json to Struct")
		fmt.Println(err.Error())
	} else {

		publishToRabbitMQ(requestBody1.OperationCode, requestBody1)

		if requestBody1.ScheduleTimeStamp != "" {
			//Push to ObjectStore
			tmp := ProcessObject{}
			temp1 := requestBody1.RefID
			temp2 := requestBody1.RefType
			tmp.Id = (temp1 + temp2)
			tmp.requestBody = requestBody1
			client.Go("token", "schedule", "newobject").StoreObject().WithKeyField("Id").AndStoreOne(tmp).Ok()
		}
	}

}
Exemplo n.º 12
0
func (h *AuthHandler) UserActivation(token string) bool {
	//respond := ""
	//check user from db
	bytes, err := client.Go("ignore", "com.duosoftware.com", "activation").GetOne().ByUniqueKey(token).Ok()
	if err == "" {
		var uList ActivationEmail
		err := json.Unmarshal(bytes, &uList)
		if err == nil || bytes == nil {
			//new user
			if err != nil {

				term.Write("Token Not Found", term.Debug)
				return false

			} else {
				//uList[0].GUUserID
				var u User
				var inputParams map[string]string
				inputParams = make(map[string]string)
				inputParams["email"] = u.EmailAddress
				inputParams["name"] = u.Name
				//Change activation status to true and save
				term.Write("Activate User  "+u.Name+" Update User "+u.UserID, term.Debug)
				email.Send("ignore", "com.duosoftware.auth", "email", "user_activated", inputParams, u.EmailAddress)
				return true
			}
		}

	} else {
		term.Write("Activation Fail ", term.Debug)
		return false

	}
	return false
}
Exemplo n.º 13
0
func getEmailData(securityToken string, domain string, class string, templateId string) (email Emailtemplate) {
	email = Emailtemplate{}

	bytes, _ := client.Go(securityToken, domain, class).GetOne().ByUniqueKey(templateId).Ok()

	email = Emailtemplate{}

	var array map[string]interface{}
	array = make(map[string]interface{})
	_ = json.Unmarshal(bytes, &array)

	for key, value := range array {
		if key != "__osHeaders" {
			if key == "Id" {
				email.Id = value.(string)
				continue
			} else if key == "Subject" {
				email.Subject = value.(string)
				continue
			} else if key == "Body" {
				email.Body = value.(string)
				continue
			} else if key == "Signature" {
				email.Signature = value.(string)
				continue
			} else if key == "Parameters" {
				email.Parameters = getParameterMap(value.(string))
			}
		}
	}

	return email
}
Exemplo n.º 14
0
//Activate user account using invitation mail send with token
//GET
//Url  /UserActivation/sdfsdfwer23rsdff
//if user activation success method will return Success
func (serv RegistationService) UserActivation(token string) string {
	respond := ""
	//check user from db
	bytes, err := client.Go("ignore", "com.duosoftware.com", "activation").GetOne().BySearching(token).Ok()
	if err == "" {
		var uList []User
		err := json.Unmarshal(bytes, &uList)
		if err == nil || bytes == nil {
			//new user
			if len(uList) == 0 {

				term.Write("User Not Found", term.Debug)

			} else {
				var u User
				u.UserID = uList[0].UserID
				u.Password = uList[0].Password
				u.Active = true
				u.ConfirmPassword = uList[0].Password
				u.Name = uList[0].Name
				u.EmailAddress = uList[0].EmailAddress

				//Change activation status to true and save
				term.Write("Activate User  "+u.Name+" Update User "+u.UserID, term.Debug)
				client.Go("ignore", "com.duosoftware.auth", "users").StoreObject().WithKeyField("EmailAddress").AndStoreOne(u).Ok()
				respond = "true"
				var Activ ActivationEmail
				Activ.EmailAddress = u.EmailAddress
				//set token empty and save
				Activ.Token = ""
				client.Go("ignore", "com.duosoftware.com", "Activation").StoreObject().WithKeyField("EmailAddress").AndStoreOne(Activ).Ok()

				Email(u.EmailAddress, Activ.Token, "Activated")
				respond = "Success"
			}
		}

	} else {
		term.Write("Activation Fail ", term.Debug)

	}

	return respond

}
Exemplo n.º 15
0
func (h *AuthHandler) GetAuthCode(ApplicationID, UserID, URI string) string {
	var a AuthCode
	a.ApplicationID = ApplicationID
	a.UserID = UserID
	a.URI = URI
	a.Code = common.RandText(10)
	client.Go("ignore", "com.duosoftware.auth", "authcode").StoreObject().WithKeyField("Code").AndStoreOne(a).Ok()
	term.Write("GetAuthCode for "+ApplicationID+" with SecurityToken :"+UserID, term.Debug)
	return a.Code
}
Exemplo n.º 16
0
func (d *Downloader) DownloadObjects() {

	nowTime := time.Now().Local()                             //current time
	addedtime := nowTime.Add(time.Duration(15 * time.Minute)) //add 15 minutes to current time
	formattedTime := addedtime.Format("20060102150405")       //formatted new time
	rawBytes, err := client.Go("efba1d6c3566e9bcfdf61a9a8d238dd8", "com.duosoftware.com", "schedule").GetMany().ByQuerying("Timestamp:[* " + formattedTime + "]").Ok()
	if len(err) != 0 {
		fmt.Println("ERROR : " + err)
	}
	d.executeObjects(rawBytes)
}
Exemplo n.º 17
0
func addCirt(GUUserID string, p PermistionRecords, s SecInfo) {
	var c Cirtificat
	var r RecordUsers
	term.Write("Methed Invoke addCirt", term.Debug)

	c.POGid = getPODID(GUUserID, p.RecordID)
	c.AccessLevel = p.AccessLevel
	c.OtherData = p.OtherData
	r.RecordID = p.RecordID
	r.UserIDs = getUsers(p.RecordID, s)
	client.Go(s.SecurityToken, s.POGDomain, "cirts").StoreObject().WithKeyField("POGid").AndStoreOne(c).Ok()
	term.Write("Methed Invoke addCirt Insearted to com.duosoftware.pog.cirts."+c.POGid, term.Debug)
	for _, element := range r.UserIDs {
		if element == GUUserID {
			return
		}
	}
	r.UserIDs = append(r.UserIDs, GUUserID)
	client.Go(s.SecurityToken, s.POGDomain, "records").StoreObject().WithKeyField("RecordID").AndStoreOne(r).Ok()
	term.Write("Methed Invoke addCirt Inserted to com.duosoftware.pog.records."+r.RecordID, term.Debug)
}
Exemplo n.º 18
0
func (h *TenantHandler) SearchTenants(Search string, since, pagesize int) []Tenant {
	bytes, err := client.Go("ignore", "com.duosoftware.tenant", "tenants").GetMany().BySearching(Search).Ok()
	var t []Tenant
	if err == "" {
		err := json.Unmarshal(bytes, &t)
		if err != nil {
			return t
		}
	}

	return t
}
Exemplo n.º 19
0
func testClient() {
	//ytes, _ := client.Go("token", "com.duosoftware.customer", "account").GetOne().BySearching("supun").Ok()

	tmp := Account{}
	tmp.Id = "999"
	tmp.name = "SVD"
	tmp.address = "X"
	client.Go("token", "com.duosoftware.customer", "account").StoreObject().WithKeyField("Id").AndStoreOne(tmp).Ok()

	//if bytes != nil {
	//	fmt.Println(bytes)
	//}
}
Exemplo n.º 20
0
func (h *TenantHandler) Autherized(TenantID string, user session.AuthCertificate) (bool, TenantAutherized) {
	bytes, err := client.Go("ignore", "com.duosoftware.tenant", "authorized").GetOne().ByUniqueKey(common.GetHash(user.UserID + "-" + TenantID)).Ok()
	if err == "" {
		var uList TenantAutherized
		err := json.Unmarshal(bytes, &uList)
		if err == nil {
			return uList.Autherized, uList
		} else {
			return false, TenantAutherized{}
		}
	} else {
		return false, TenantAutherized{}
	}
}
Exemplo n.º 21
0
func (h *TenantHandler) GetTenant(TenantID string) Tenant {
	bytes, err := client.Go("ignore", "com.duosoftware.tenant", "tenants").GetOne().ByUniqueKey(TenantID).Ok()
	var t Tenant
	if err == "" {
		err := json.Unmarshal(bytes, &t)
		if err == nil {
			return t
		} else {
			return t
		}
	} else {
		return t
	}
}
Exemplo n.º 22
0
func (h *TenantHandler) GetTenantsForUser(UserID string) []TenantMinimum {
	bytes, err := client.Go("ignore", "com.duosoftware.tenant", "userstenantmappings").GetOne().ByUniqueKey(UserID).Ok()
	var t UserTenants
	if err == "" {
		err := json.Unmarshal(bytes, &t)
		if err == nil {
			return t.TenantIDs
		} else {
			return []TenantMinimum{}
		}
	} else {
		return []TenantMinimum{}
	}
}
Exemplo n.º 23
0
func (h *AuthHandler) AppAutherize(ApplicationID, UserID string) bool {
	bytes, err := client.Go("ignore", "com.duosoftware.auth", "atherized").GetOne().ByUniqueKey(ApplicationID + "-" + UserID).Ok()
	term.Write("AppAutherize For Application "+ApplicationID+" UserID "+UserID, term.Debug)
	if err == "" {
		if bytes != nil {
			var uList AppAutherize
			err := json.Unmarshal(bytes, &uList)
			if err == nil {
				return true
			}
		}
	} else {
		term.Write("AppAutherize Error "+err, term.Error)
	}
	return false
}
Exemplo n.º 24
0
func getUsers(RecordID string, s SecInfo) []string {
	term.Write("Methed Invoke getUsers", term.Debug)
	var c RecordUsers
	//RecID = getPODID(UserID, recordID)
	bytes, err := client.Go(s.SecurityToken, s.POGDomain, "records").GetOne().ByUniqueKey(RecordID).Ok()
	//var t Tenant
	if err == "" {
		err := json.Unmarshal(bytes, &c)
		if err == nil {
			return c.UserIDs
		} else {
			return c.UserIDs
		}
	} else {
		return c.UserIDs
	}
}
Exemplo n.º 25
0
func getCirt(UserID, recordID string, s SecInfo) Cirtificat {
	term.Write("Methed Invoke getCirt", term.Debug)
	var c Cirtificat
	RecID := getPODID(UserID, recordID)
	bytes, err := client.Go(s.SecurityToken, s.POGDomain, "cirts").GetOne().ByUniqueKey(RecID).Ok()
	//var t Tenant
	if err == "" {
		err := json.Unmarshal(bytes, &c)
		if err == nil {
			return c
		} else {
			term.Write("Methed Invoke getCirt :"+err.Error(), term.Error)
			return c
		}
	} else {
		term.Write("Methed Invoke getCirt :"+err, term.Error)
		return c
	}
}
Exemplo n.º 26
0
//User login
func (serv RegistationService) Login(l Login) {
	bytes, err := client.Go("ignore", "com.duosoftware.auth", "users").GetOne().ByUniqueKey(l.EmailAddress).Ok()
	fmt.Println(l.EmailAddress, l.Password)
	fmt.Println("19")
	if err == "" {
		fmt.Println("20")
		if bytes != nil {
			fmt.Println("21")
			newUser := User{}
			//uList = make([]User, 0)
			err := json.Unmarshal(bytes, &newUser)
			fmt.Println("22")
			fmt.Println("<<<<<<<<<<<", newUser)

			if err == nil {
				fmt.Println("23")
				if newUser.Password == l.Password && newUser.EmailAddress == l.EmailAddress {
					fmt.Println("24")
					serv.ResponseBuilder().SetResponseCode(200).Write([]byte(newUser.Name))
					//term.Write("password incorrect", term.Error)
				} else {
					fmt.Println("25")
					serv.ResponseBuilder().SetResponseCode(201).Write([]byte("Password Wrong "))
				}
			} else {
				fmt.Println("26")
				if err != nil {
					fmt.Println("27")
					term.Write("Login  user Error "+err.Error(), term.Error)
				}
			}
		}
	} else {
		fmt.Println("28")
		term.Write("Login  user  Error "+err, term.Error)
		serv.ResponseBuilder().SetResponseCode(201).Write([]byte(err))
	}

}
Exemplo n.º 27
0
func (h *TenantHandler) AcceptRequest(u session.AuthCertificate, securityLevel, RequestToken string, accept bool) bool {
	bytes, err := client.Go("ignore", "com.duosoftware.tenant", "userrequest").GetOne().ByUniqueKey(RequestToken).Ok()
	var t InviteUserRequest
	if err == "" {
		err := json.Unmarshal(bytes, &t)
		if err != nil {
			if securityLevel == "" {
				securityLevel = t.SecurityLevel
			}
			if accept {
				h.AddUsersToTenant(t.TenantID, t.Name, t.UserID, securityLevel)
				return true
			} else {
				return true
			}
		} else {
			return false
		}
	} else {
		return false
	}
}
Exemplo n.º 28
0
func (A BulkTransferService) Transfer(c messaging.BulkHeader) {
	for _, detail := range c.Details {
		switch detail.Type {
		case "id":
			bytes, err := client.Go("", c.Source, detail.Class).GetOne().ByUniqueKey(detail.Params["key"].(string)).Ok()
			isErr, m := A.getMap(bytes, err)
			if !isErr {
				keyField := detail.Params["keyField"].(string)
				client.Go("", c.Dest, detail.Class).StoreObject().WithKeyField(keyField).AndStoreOne(m).Ok()
			} else {
				fmt.Println("K OBJECT NOT FOUND!!!!")
			}
			break
		case "filter":
			bytes, err := client.Go("", c.Source, detail.Class).GetMany().ByQuerying(detail.Params["filter"].(string)).Ok()
			isErr, m := A.getMapArray(bytes, err)
			if !isErr {
				keyField := detail.Params["keyField"].(string)
				client.Go("", c.Dest, detail.Class).StoreObject().WithKeyField(keyField).AndStoreMany(m).Ok()
			} else {
				fmt.Println("F OBJECT NOT FOUND!!!!")
			}
			break
		case "search":
			bytes, err := client.Go("", c.Source, detail.Class).GetMany().BySearching(detail.Params["filter"].(string)).Ok()
			isErr, m := A.getMapArray(bytes, err)
			if !isErr {
				keyField := detail.Params["keyField"].(string)
				client.Go("", c.Dest, detail.Class).StoreObject().WithKeyField(keyField).AndStoreMany(m).Ok()
			} else {
				fmt.Println("S OBJECT NOT FOUND!!!!")
			}
			break
		case "all":
			break
		default:
			fmt.Println("UNKNOWN OPERATION!!!!")
			break
		}
	}

	A.ResponseBuilder().SetResponseCode(200).WriteAndOveride([]byte("{}"))
	return
}
Exemplo n.º 29
0
//Save user using Authlib
func SaveUser(u User) string {
	term.Write("SaveUser saving user  "+u.Name, term.Debug)
	respond := ""
	token := randToken()
	fmt.Println("3")
	fmt.Println(">>>>>>>>>>>>>>>")
	fmt.Println(u.EmailAddress)
	fmt.Println("<<<<<<<<<<<<<<<")
	//bytes, err := client.Go("ignore", "com.duosoftware.auth", "users").GetOne().ByQuerying("EmailAddress :" + "*****@*****.**").Ok()
	bytes, err := client.Go("ignore", "com.duosoftware.auth", "users").GetOne().ByUniqueKey(u.EmailAddress).Ok()

	fmt.Println("{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{")
	fmt.Println(string(bytes))
	fmt.Println("}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}")
	fmt.Println("4")
	if err == "" {
		var uList []User
		uList = make([]User, 0)
		err := json.Unmarshal(bytes, &uList)
		if err == nil || bytes == nil {
			fmt.Println("5")
			//new user

			fmt.Println(len(uList), "LLLLLLLLLLLLLLLLLLLL")
			if len(uList) == 0 {
				u.UserID = common.GetGUID()
				term.Write("SaveUser saving user"+u.Name+" New User "+u.UserID, term.Debug)
				client.Go("ignore", "com.duosoftware.auth", "users").StoreObject().WithKeyField("EmailAddress").AndStoreOne(u).Ok()
				respond = "true"
				fmt.Println("6")
				//save Activation mail details
				//EmailAddress and Token
				//EmailAddress KeyProperty
				var Activ ActivationEmail
				Activ.EmailAddress = u.EmailAddress
				Activ.Token = token
				client.Go("ignore", "com.duosoftware.com", "activation").StoreObject().WithKeyField("EmailAddress").AndStoreOne(Activ).Ok()
				fmt.Println("7")
				Email(u.EmailAddress, token, "Activation")

			} else if len(uList) == 1 {
				//Alredy in  Registerd user
				//term.Write("User Already Registerd  #"+err.Error(), term.Error)
				fmt.Println("User Already Registerd")

			}
		} else {
			fmt.Println("ERRRRRR")
			//term.Write("SaveUser saving user store Error #"+err.Error(), term.Error)
			respond = "false"

		}
	} else {
		//term.Write("SaveUser saving user fetech Error #"+err, term.Error)
		fmt.Println("errrrr")
		respond = "false"
	}
	fmt.Println("8")
	u.Password = "******"
	u.ConfirmPassword = "******"
	return respond
}
Exemplo n.º 30
0
func (f *FileManager) Store(request *messaging.FileRequest) messaging.FileResponse { // store disk on database

	fileResponse := messaging.FileResponse{}

	if len(request.Body) == 0 {

		//WHEN REQUEST COMES FROM A REST INTERFACE

		file, header, err := request.WebRequest.FormFile("file")

		if err != nil {
			fileResponse.IsSuccess = false
			fileResponse.Message = err.Error()
		}

		out, err := os.Create(header.Filename)
		if err != nil {
			fileResponse.IsSuccess = false
			fileResponse.Message = err.Error()
		}

		// write the content from POST to the file
		_, err = io.Copy(out, file)
		if err != nil {
			fileResponse.IsSuccess = false
			fileResponse.Message = err.Error()
		}

		file2, err2 := ioutil.ReadFile(header.Filename)

		if err2 != nil {
			fileResponse.IsSuccess = false
			fileResponse.Message = err.Error()
		}

		if checkIfFile(header.Filename) == "xlsx" {
			SaveExcelEntries(header.Filename, request.Parameters["namespace"])
		}

		convertedBody := string(file2[:])
		base64Body := common.EncodeToBase64(convertedBody)

		//store file in the DB as a single file
		obj := FileData{}
		obj.Id = request.Parameters["id"]
		obj.FileName = header.Filename
		obj.Body = base64Body

		headerToken := request.WebRequest.Header.Get("securityToken")

		var extraMap map[string]interface{}
		extraMap = make(map[string]interface{})
		extraMap["File"] = "excelFile"
		fmt.Println(headerToken)
		fmt.Println("Namespace : " + request.Parameters["namespace"])
		fmt.Println("Class : " + request.Parameters["class"])
		//client.GoExtra(headerToken, request.Parameters["namespace"], request.Parameters["class"], extraMap).StoreObject().WithKeyField("Id").AndStoreOne(obj).FileOk()

		fmt.Fprintf(request.WebResponse, "File uploaded successfully : ")
		fmt.Fprintf(request.WebResponse, header.Filename)

		//close the files
		err = out.Close()
		err = file.Close()

		if err != nil {
			fileResponse.IsSuccess = false
			fileResponse.Message = err.Error()
		}

		//remove the temporary stored file from the disk
		err2 = os.Remove(header.Filename)

		if err2 != nil {
			fileResponse.IsSuccess = false
			fileResponse.Message = err2.Error()
		}

		if err == nil && err2 == nil {
			fileResponse.IsSuccess = true
			fileResponse.Message = "Storing file successfully completed"
		} else {
			fileResponse.IsSuccess = false
			fileResponse.Message = "Storing file was unsuccessfull!" + "\n" + err.Error() + "\n" + err2.Error()
		}

	} else {

		//WHEN REQUEST COMES FROM A NON REST INTERFACE

		convertedBody := string(request.Body[:])
		base64Body := common.EncodeToBase64(convertedBody)

		//store file in the DB as a single file
		obj := FileData{}
		obj.Id = request.Parameters["id"]
		obj.FileName = request.FileName
		obj.Body = base64Body

		client.Go("securityToken", request.Parameters["namespace"], request.Parameters["class"]).StoreObject().WithKeyField("Id").AndStoreOne(obj).FileOk()

		fileResponse.IsSuccess = true
		fileResponse.Message = "Storing file successfully completed"

	}

	return fileResponse
}