Exemplo n.º 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"
	}

}
Exemplo n.º 2
0
func (this *SettingController) ChangePasswordSave() {
	redirectURL := this.GetString("epic_sub_site")
	if "" == redirectURL {
		redirectURL = config.GetRedirectURL()
	}
	this.Data["epic_sub_site"] = redirectURL
	this.Data["redirectURL"] = redirectURL
	this.Data["succ"] = false
	passwordOld := this.GetString("PasswordOld")
	password := this.GetString("Password")
	passwordRe := this.GetString("PasswordRe")
	if len(passwordOld) == 0 || len(password) == 0 || len(passwordRe) == 0 {
		this.Data["msg"] = "修改密码失败,缺少参数"
		this.TplNames = "change_password_succeed.html"
		return
	}
	if password != passwordRe {
		this.Data["msg"] = "修改密码失败,两次密码输入不一致"
		this.TplNames = "change_password_succeed.html"
		return
	}
	token := this.Ctx.GetCookie("epic_user_token")
	ok, userId := tools.VerifyToken(token)
	if len(token) == 0 || !ok {
		this.Data["msg"] = "修改密码失败,请重新登录"
		this.TplNames = "change_password_succeed.html"
		return
	}

	ok, user := auth.GetUserInfoFrmDB(userId)
	if !ok {
		this.Data["msg"] = "修改密码失败,用户不存在"
		this.TplNames = "change_password_succeed.html"
		return
	}
	ok = auth.VerifyPassword(passwordOld, user.Password)
	if !ok {
		this.Data["msg"] = "修改密码失败,当前密码验证错误"
		this.TplNames = "change_password_succeed.html"
		return
	}
	err := auth.SaveNewPassword(&user, password)
	if err != nil {
		beego.Error("密码修改失败:", err)
		this.Data["msg"] = "修改密码失败,请联系管理员"
		this.TplNames = "change_password_succeed.html"
		return
	}
	this.Data["msg"] = "修改密码成功,稍后将进行自动跳转"
	this.Data["succ"] = true
	this.TplNames = "change_password_succeed.html"
}
Exemplo n.º 3
0
func (this *SocialAuthController) ConnectPost() {
	token := this.Ctx.GetCookie("epic_user_token")
	ok, userId := tools.VerifyToken(token)
	if !ok || len(userId) == 0 {
		this.Redirect("/", 302)
		return
	}
	password := this.GetString("Password")
	userName := this.GetString("UserName")
	if len(userId) == 0 || len(password) == 0 || len(userName) == 0 {
		this.Data["userId"] = userId
		this.TplNames = "connect.html"
		this.Data["error"] = "[用户名]或者[密码]为空"
		this.Data["state"] = "注册失败"
		this.Data["msg"] = "[用户名]或者[邮箱]已被注册"
		return
	}
	isExist := auth.UserIsExists(userName, userName)
	if isExist {
		this.Data["userId"] = userId
		this.TplNames = "connect.html"
		this.Data["error"] = "[用户名]或者[邮箱]已被注册"
		this.Data["state"] = "注册失败"
		this.Data["msg"] = "[用户名]或者[邮箱]已被注册"
		return
	}
	user := models.User{}
	user.Password = password
	user.UserName = userName
	user.Id, _ = strconv.Atoi(userId)
	err := auth.ConnectUpdateUser(&user, password)
	if err != nil {
		this.Data["userId"] = userId
		this.TplNames = "connect.html"
		this.Data["error"] = err.Error()
		this.Data["state"] = "注册失败"
		beego.Error("注册失败-插入数据库出错", err)
		this.Data["msg"] = err.Error()
		return
	}

	subSitesConf := config.GetSubSites()
	this.Data["srcs"] = strings.Split(subSitesConf, ",")
	this.Data["token"] = token
	this.Data["state"] = "注册成功"
	this.Data["msg"] = "3秒后自动跳转!!"
	this.Data["succ"] = true
	this.Data["redirectURL"] = config.GetRedirectURL()
	this.TplNames = "succeed.html"
}
Exemplo n.º 4
0
func (this *RegisterController) Succeed() {
	this.Data["appname"] = "单点登录服务"
	this.Data["state"] = "注册成功"
	this.Data["msg"] = "用户已经登录"
	this.TplNames = "succeed.html"
	this.Data["succ"] = true

	redirectURL := this.GetString("redirectURL")
	if "" == redirectURL {
		redirectURL = config.GetRedirectURL()
	}

	this.Data["redirectURL"] = redirectURL
}
Exemplo n.º 5
0
func (this *RegisterController) Get() {
	this.Data["AppUrl"] = beego.AppConfig.String("appUrl")

	this.TplNames = "register.html"

	redirectURL := this.GetString("redirectURL")
	if "" == redirectURL {
		redirectURL = this.GetString("epic_sub_site")

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

	this.Data["redirectURL"] = redirectURL
}
Exemplo n.º 6
0
func (this *RegisterController) Register() {
	redirectURL := this.GetString("redirectURL")
	if "" == redirectURL {
		redirectURL = config.GetRedirectURL()
	}

	this.Data["redirectURL"] = redirectURL

	user := models.User{}
	err := this.ParseForm(&user)
	this.TplNames = "succeed.html"
	this.Data["succ"] = true
	if err != nil {
		beego.Error("注册失败-表单解析出错", err)
		this.Data["state"] = "注册失败"
		this.Data["msg"] = err.Error()
		this.Data["succ"] = false
		return
	}
	ok := setting.Captcha.VerifyReq(this.Ctx.Request)
	if !ok {
		this.Data["state"] = "注册失败"
		this.Data["msg"] = "验证码错误"
		this.Data["succ"] = false
		return
	}

	isExist := auth.UserIsExists(user.UserName, user.Email)
	if isExist {
		this.Data["state"] = "注册失败"
		this.Data["msg"] = "[用户名]或者[邮箱]已被注册"
		this.Data["succ"] = false
		return
	}
	err = auth.RegisterUser(&user, user.UserName, user.Email, user.Password)
	if err != nil {
		this.Data["state"] = "注册失败"
		beego.Error("注册失败-插入数据库出错", err)
		this.Data["msg"] = err.Error()
		this.Data["succ"] = false
		return
	}
	this.Data["state"] = "注册成功"
	this.Data["msg"] = "恭喜!!将进行自动跳转,请稍等..."

}
Exemplo n.º 7
0
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"
}
Exemplo n.º 8
0
func (this *LoginController) Get() {
	this.Data["AppUrl"] = beego.AppConfig.String("appUrl")
	this.TplNames = "login.html"
	loginRedirect := strings.TrimSpace(this.GetString("epic_sub_site"))
	if tools.IsMatchHost(loginRedirect) == false {
		loginRedirect = "/"
	}
	if len(loginRedirect) > 0 {
		this.Data["epic_sub_site"] = loginRedirect
	}

	redirectURL := this.GetString("redirectURL")
	if "" == redirectURL {
		redirectURL = this.GetString("epic_sub_site")

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

	this.Data["redirectURL"] = redirectURL
}
Exemplo n.º 9
0
func (this *SettingController) ChangePassword() {

	this.Data["AppUrl"] = beego.AppConfig.String("appUrl")
	this.TplNames = "change_password.html"
	redirectURL := this.GetString("redirectURL")
	if "" == redirectURL {
		redirectURL = this.GetString("epic_sub_site")
		if "" == redirectURL {
			redirectURL = config.GetRedirectURL()
		}
	}
	this.Data["redirectURL"] = redirectURL
	this.Data["epic_sub_site"] = redirectURL
	ctx := this.Ctx
	token := ctx.GetCookie("epic_user_token")
	ok, _ := tools.VerifyToken(token)
	if len(token) == 0 || !ok {
		ctx.Redirect(302, "/")
		return
	}

}