Ejemplo n.º 1
0
// 是否已经登录
func (as *AuthService) HasLogin() bool {
	var result bool = false
	as.Factory().CookieService.WithContext(as.ctx, func() {
		var usernameCookie = as.Factory().CookieService.Get(authUsername)
		if usernameCookie != "" {
			var usernameBody = utils.DES().Decrypt(usernameCookie)
			if strings.HasPrefix(usernameBody, fUsername) {
				as.Factory().CookieService.Set(authUsername, usernameCookie)
				result = true
			}
		}
	})
	return result
}
Ejemplo n.º 2
0
// 登录
func (as *AuthService) Login(user *models.User) map[string]string {
	data := user.Login()
	for k, _ := range data {
		if strings.Contains(k, "Error") {
			return data
		}
	}

	as.Factory().CookieService.WithContext(as.ctx, func() {
		var rolestr = fmt.Sprintf("%s", user.Role)
		var value = utils.DES().Encrypt(fUsername + seq + user.Id + seq + rolestr + seq + user.Username)
		as.Factory().CookieService.SetWithT(authUsername, value, c_timeout)
	})
	return data
}
Ejemplo n.º 3
0
// 获取登录者信息
func (as *AuthService) GetAuthUser() *models.User {
	user := &models.User{}
	as.Factory().CookieService.WithContext(as.ctx, func() {
		var usernameCookie = as.Factory().CookieService.Get(authUsername)
		if usernameCookie != "" {
			var usernameBody = utils.DES().Decrypt(usernameCookie)
			if strings.HasPrefix(usernameBody, fUsername) {
				authStr := strings.Split(usernameBody, seq)
				user.Id = authStr[1]
				user.Role = models.Role(authStr[2])
				user.Username = authStr[3]
			}
		}
	})
	return user
}