Exemplo n.º 1
0
func (this *OAuthController) Post() {
	this.Forbbiden("is", "guest")

	password := this.GetString("password")
	token := this.GetString("token")
	username := this.Data["username"].(string)

	user := models.User{}
	oa := models.OAuth{}

	result, _ := user.Login(username, password)

	if result {
		u, err := user.GetUser(0, username, "", "")
		if err != nil {
			log.Warnln("get uid failed.")
			this.Data["json"] = map[string]interface{}{
				"result": false,
				"msg":    "get uid failed.",
				"refer":  nil,
			}
		}

		if oa.GithubBind(token, "github", u.Id) {
			this.Data["json"] = map[string]interface{}{
				"result": true,
				"msg":    "binding success",
				"refer":  nil,
			}
		} else {
			this.Data["json"] = map[string]interface{}{
				"result": false,
				"msg":    "binding failed",
				"refer":  nil,
			}
		}

	} else {
		this.Data["json"] = map[string]interface{}{
			"result": false,
			"msg":    "wrong password.",
			"refer":  nil,
		}
	}

	this.ServeJson()

}
Exemplo n.º 2
0
func (this *LoginController) Post() {
	this.Forbbiden("not", "guest")

	user := models.User{}

	username := this.GetString("username")
	password := this.GetString("password")

	if result, lev := user.Login(username, password); result {
		user, err := user.GetUser(0, username, "", "")
		if err != nil {
			this.Data["json"] = map[string]interface{}{
				"result": false,
				"msg":    "login failed, get user info failed",
				"refer":  nil,
			}
		} else {
			this.SetSession("username", username)
			this.SetSession("userid", fmt.Sprintf("%d", user.Id))
			this.SetSession("level", lev)

			this.Data["json"] = map[string]interface{}{
				"result": true,
				"msg":    "login success",
				"refer":  nil,
			}
		}

	} else {
		this.Data["json"] = map[string]interface{}{
			"result": false,
			"msg":    "login failed",
			"refer":  nil,
		}
	}

	this.ServeJson()
}