Beispiel #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()

}