예제 #1
0
func (this *SocialAuthController) Connect() {
	identify := this.GetSession("custom_userSocial_identify")
	userName, ok := this.GetSession("custom_userSocial_userName").(string)

	if ok && len(userName) > 0 {
		userNames := strings.Split(userName, "_")
		this.Data["intrant"] = userNames[0] + "用户“" + userNames[1] + "”,"
	}
	userId, isInit := auth.InitConnect(identify.(string))
	token, err := tools.CreateToken(userId)
	this.Data["userId"] = userId
	if err == nil {
		this.Ctx.SetCookie("epic_user_token", token)
	} else {
		fmt.Println("生成token失败-" + err.Error())
	}
	if isInit {
		this.Data["token"] = token
		this.Data["epic_sub_site"] = config.GetRedirectURL()
		subSitesConf := config.GetSubSites()
		this.Data["srcs"] = strings.Split(subSitesConf, ",")
		this.TplNames = "loginRedirect.html"
	} else {
		this.TplNames = "connect.html"
	}

}
예제 #2
0
파일: login.go 프로젝트: EPICPaaS/account
func (this *LoginController) Login() {
	redirectURL := this.GetString("redirectURL")
	if "" == redirectURL {
		redirectURL = this.GetString("epic_sub_site")

		if "" == redirectURL {
			redirectURL = config.GetRedirectURL()
		}
	}

	this.Data["redirectURL"] = redirectURL

	this.Data["AppUrl"] = beego.AppConfig.String("appUrl")
	username := this.GetString("UserName")
	password := this.GetString("Password")
	loginRedirect := this.GetString("epic_sub_site")
	ok, user := auth.VerifyUser(username, password)
	if !ok {
		this.TplNames = "login.html"
		this.Data["error"] = "用户名或密码错误!"
		this.Data["epic_sub_site"] = loginRedirect
		this.Data["UserName"] = username
		return
	}
	//生成用户登录token
	token, err := tools.CreateToken(strconv.Itoa(user.Id))
	if len(token) == 0 || err != nil {
		this.TplNames = "login.html"
		this.Data["error"] = "生成Token失败"
		this.Data["epic_sub_site"] = loginRedirect
		this.Data["UserName"] = username
		return
	}
	this.Ctx.SetCookie("epic_user_token ", token)
	this.Data["token"] = token
	this.Data["epic_sub_site"] = loginRedirect

	subSitesConf := config.GetSubSites()

	this.Data["srcs"] = strings.Split(subSitesConf, ",")

	this.TplNames = "loginRedirect.html"
}