コード例 #1
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
}
コード例 #2
0
ファイル: authlib.go プロジェクト: sajeetharan/v6engine
func (A Auth) Login(username, password, domain string) (outCrt AuthCertificate) {
	h := newAuthHandler()
	u, err := h.Login(username, password)
	if err == "" {
		//fmt.Println("login succeful")
		//securityToken := common.GetGUID()
		outCrt.ClientIP = A.Context.Request().RemoteAddr
		outCrt.DataCaps = GetDataCaps(domain, u.UserID)
		outCrt.Email = u.EmailAddress
		outCrt.UserID = u.UserID
		outCrt.Name = u.Name
		outCrt.SecurityToken = common.GetGUID()
		outCrt.Domain = domain
		outCrt.Username = u.EmailAddress
		outCrt.Otherdata = make(map[string]string)
		//outCrt.Otherdata["Tempkey"] = "No"
		th := TenantHandler{}
		tlist := th.GetTenantsForUser(u.UserID)
		b, _ := json.Marshal(tlist)
		outCrt.Otherdata["TenentsAccessible"] = string(b[:])
		//outCrt = AuthCertificate{u.UserID, u.EmailAddress, u.Name, u.EmailAddress, securityToken, "http://192.168.0.58:9000/instaltionpath", "#0so0936#sdasd", "IPhere"}
		h.AddSession(outCrt)
		return
	} else {
		A.ResponseBuilder().SetResponseCode(401).WriteAndOveride([]byte("Invalid user name password"))
		return
	}
}
コード例 #3
0
ファイル: session.go プロジェクト: sajeetharan/v6engine
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"
}
コード例 #4
0
ファイル: stat.go プロジェクト: sajeetharan/v6engine
func Add(stats States) string {
	if isRuning {
		if stats.ID == "" {
			stats.ID = common.GetGUID()
			stats.CreatedTime = time.Now()
		}
		Data = append(Data, stats)
	}
	return stats.ID
}
コード例 #5
0
ファイル: authHandler.go プロジェクト: sajeetharan/v6engine
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
}
コード例 #6
0
ファイル: authlib.go プロジェクト: sajeetharan/v6engine
func (A Auth) Authorize(SecurityToken string, ApplicationID string) (a AuthCertificate) {
	h := newAuthHandler()
	//var a AuthCertificate
	c, err := h.GetSession(SecurityToken, "Nil")
	if err == "" {
		if h.AppAutherize(ApplicationID, c.UserID) == true {
			a = c
			a.ClientIP = A.Context.Request().RemoteAddr
			a.SecurityToken = common.GetGUID()
			h.AddSession(a)
			return a
		} else {
			A.ResponseBuilder().SetResponseCode(401).WriteAndOveride([]byte("Application ID " + ApplicationID + " not Atherized"))
			return
		}

	}
	A.ResponseBuilder().SetResponseCode(401).WriteAndOveride([]byte("Session or Application not exist"))

	return
}
コード例 #7
0
ファイル: usersvc.go プロジェクト: sajeetharan/v6engine
//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
}
コード例 #8
0
ファイル: authlib.go プロジェクト: sajeetharan/v6engine
func (A Auth) GetGUID() string {
	return common.GetGUID()
}