예제 #1
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
}
예제 #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
}
예제 #3
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)
	}
}
예제 #4
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
}
예제 #5
0
func (h *AuthHandler) ForgetPassword(emailaddress string) bool {
	u, error := h.GetUser(emailaddress)
	if error == "" {
		passowrd := common.RandText(6)
		u.ConfirmPassword = passowrd
		u.Password = passowrd
		term.Write("Password : "******"email"] = u.EmailAddress
		inputParams["name"] = u.Name
		inputParams["password"] = passowrd
		email.Send("ignore", "com.duosoftware.auth", "email", "user_resetpassword", inputParams, u.EmailAddress)
		term.Write("E Mail Sent", term.Debug)
		return true
	}
	return false
}