Exemple #1
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
}
Exemple #2
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"
}
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
	}
}
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{}
	}
}
Exemple #5
0
func getPODID(UserID, recordID string) string {
	term.Write("Methed Invoke getPODID", term.Debug)
	return common.GetHash(UserID + "-" + recordID)
}