diff --git a/app/controllers/AuthController.go b/app/controllers/AuthController.go index 8cd0d5b..6af77e7 100644 --- a/app/controllers/AuthController.go +++ b/app/controllers/AuthController.go @@ -85,8 +85,14 @@ func (c Auth) Logout() revel.Result { // 体验一下 func (c Auth) Demo() revel.Result { - c.doLogin(configService.GetGlobalStringConfig("demoUsername"), configService.GetGlobalStringConfig("demoPassword")) - return c.Redirect("/note") + email := configService.GetGlobalStringConfig("demoPassword") + pwd := configService.GetGlobalStringConfig("demoPassword"); + userInfo := authService.Login(email, pwd) + if userInfo.Email != "" { + c.SetSession(userInfo) + return c.Redirect("/note") + } + return nil } //-------- diff --git a/app/controllers/OauthController.go b/app/controllers/OauthController.go deleted file mode 100644 index 8c283d4..0000000 --- a/app/controllers/OauthController.go +++ /dev/null @@ -1,70 +0,0 @@ -package controllers - -import ( - "code.google.com/p/goauth2/oauth" - "github.com/revel/revel" - "github.com/leanote/leanote/app/lea/netutil" - . "github.com/leanote/leanote/app/lea" - "encoding/json" - "fmt" -) - -type Oauth struct { - BaseController -} - -var oauthCfg = &oauth.Config{ - ClientId: "3790fbf1fc14bc6c5d85", - ClientSecret: "e9dadfe601c7caa6df9b33db3e7539945c60dfa2", - AuthURL: "https://github.com/login/oauth/authorize", - TokenURL: "https://github.com/login/oauth/access_token", - RedirectURL: "http://leanote.com/oauth/githubCallback", - Scope: "user", -} - -// 用户允许后, github返回到leanote -// 通过code得到token -// https://github.com/login/oauth/authorize?access_type=&approval_prompt=&client_id=3790fbf1fc14bc6c5d85&redirect_uri=http%3A%2F%2F127.0.0.1%3A8080%2Foauth2callback&response_type=code&scope=user&state= -func (c Oauth) GithubCallback(code string) revel.Result { - t := &oauth.Transport{Config: oauthCfg} - - // Exchange the received code for a token - tok, err := t.Exchange(code) - token := tok.AccessToken - if err != nil || token == "" { - c.RenderArgs["title"] = "error" - return c.RenderTemplate("oauth/oauth_callback_error.html") - } - - // 得到用户信息 - profileInfoURL := "https://api.github.com/user" - url := fmt.Sprintf("%s?access_token=%s", profileInfoURL, token) - content, err2 := netutil.GetContent(url) - if err2 != nil { - c.RenderArgs["title"] = "error" - return c.RenderTemplate("oauth/oauth_callback_error.html") - } - // 转成map - profileInfo := map[string]interface{}{} - Log(string(content)) - err2 = json.Unmarshal(content, &profileInfo) - if err2 != nil { - c.RenderArgs["title"] = "error" - return c.RenderTemplate("oauth/oauth_callback_error.html") - } - - usernameI := profileInfo["login"] - - username, _ := usernameI.(string) - userId := username - - // 注册 - isExists, userInfo := authService.ThirdRegister("github", userId, username) - c.RenderArgs["isExists"] = isExists - c.RenderArgs["userInfo"] = userInfo - - // 登录之 - c.SetSession(userInfo) - - return c.Redirect("/note") -} diff --git a/app/views/home/find_password.html b/app/views/home/find_password.html index 9971d7a..1113cb9 100644 --- a/app/views/home/find_password.html +++ b/app/views/home/find_password.html @@ -27,7 +27,7 @@ {{msg . "home"}}
- leanote © 2014 + leanote © 2014-2015
diff --git a/app/views/home/find_password2.html b/app/views/home/find_password2.html index 687e6b7..e724457 100644 --- a/app/views/home/find_password2.html +++ b/app/views/home/find_password2.html @@ -36,7 +36,7 @@ {{msg . "home"}} diff --git a/app/views/home/find_password2_timeout.html b/app/views/home/find_password2_timeout.html index bf7800c..4cec72c 100644 --- a/app/views/home/find_password2_timeout.html +++ b/app/views/home/find_password2_timeout.html @@ -21,7 +21,7 @@ {{msg . "home"}} diff --git a/app/views/home/header.html b/app/views/home/header.html index c69da38..2fdede0 100644 --- a/app/views/home/header.html +++ b/app/views/home/header.html @@ -43,7 +43,7 @@ function log(o) { Français 简体中文 - +