merged with new team domain changes and added signup/login links for gitlab

This commit is contained in:
JoramWilander
2015-07-22 10:12:28 -04:00
parent 03528b9619
commit 62c0603c50
9 changed files with 50 additions and 36 deletions
+6 -6
View File
@@ -1224,17 +1224,17 @@ func getStatuses(c *Context, w http.ResponseWriter, r *http.Request) {
}
func GetAuthorizationCode(c *Context, w http.ResponseWriter, r *http.Request, service, redirectUri string) {
params := mux.Vars(r)
teamName := params["team"]
teamId := r.FormValue("id")
if len(teamId) != 26 {
c.Err = model.NewAppError("GetAuthorizationCode", "Invalid team id", "team_id="+teamId)
if len(teamName) == 0 {
c.Err = model.NewAppError("GetAuthorizationCode", "Invalid team name", "team_name="+teamName)
c.Err.StatusCode = http.StatusBadRequest
return
}
// Make sure team exists
if result := <-Srv.Store.Team().Get(teamId); result.Err != nil {
if result := <-Srv.Store.Team().GetByName(teamName); result.Err != nil {
c.Err = result.Err
return
}
@@ -1249,7 +1249,7 @@ func GetAuthorizationCode(c *Context, w http.ResponseWriter, r *http.Request, se
endpoint := utils.Cfg.SSOSettings[service].AuthEndpoint
state := model.HashPassword(clientId)
authUrl := endpoint + "?response_type=code&client_id=" + clientId + "&redirect_uri=" + url.QueryEscape(redirectUri+"?id="+teamId) + "&state=" + url.QueryEscape(state)
authUrl := endpoint + "?response_type=code&client_id=" + clientId + "&redirect_uri=" + url.QueryEscape(redirectUri+"?team="+teamName) + "&state=" + url.QueryEscape(state)
http.Redirect(w, r, authUrl, http.StatusFound)
}
+2 -2
View File
@@ -26,8 +26,8 @@
"SSOSettings": {
"gitlab": {
"Allow": true,
"Secret" : "8526ada64f38a1a67cafe6650d54310f1484f8a5d06ad23abb9f8e4b8af1c429",
"Id": "0af4138195d246d5d4e958a93100379066bb087fa9892cd323b0c97bbd696008",
"Secret" : "0495d3d6e528d91ba46605622a3645a8409ac5971ee287b1c3a6519fe27e6f6a",
"Id": "87a4aeb746c67e87a54df78f6eccf85229dd30a3a797bfdb423b82ba4e749cd0",
"AuthEndpoint": "http://dockerhost:8080/oauth/authorize",
"TokenEndpoint": "http://dockerhost:8080/oauth/token",
"UserApiEndpoint": "http://dockerhost:8080/api/v3/user"
+1 -1
View File
@@ -113,7 +113,7 @@ module.exports = React.createClass({
<button type="submit" className="btn btn-primary">Sign in</button>
</div>
<div className="form-group form-group--small">
<span><a href="#">{"Log in with GitLab"}</a></span>
<span><a href={"/"+teamName+"/login/gitlab"}>{"Log in with GitLab"}</a></span>
</div>
<div className="form-group form-group--small">
<span><a href="/find_team">{"Find other " + strings.TeamPlural}</a></span>
@@ -46,7 +46,7 @@ module.exports = React.createClass({
function(data) {
client.track('signup', 'signup_user_02_complete');
client.loginByEmail(this.props.domain, this.state.user.email, this.state.user.password,
client.loginByEmail(this.props.teamName, this.state.user.email, this.state.user.password,
function(data) {
UserStore.setLastEmail(this.state.user.email);
UserStore.setCurrentUser(data);
@@ -58,7 +58,7 @@ module.exports = React.createClass({
}.bind(this),
function(err) {
if (err.message == "Login failed because email address has not been verified") {
window.location.href = "/verify_email?email="+ encodeURIComponent(this.state.user.email) + "&domain=" + encodeURIComponent(this.props.domain);
window.location.href = "/verify_email?email="+ encodeURIComponent(this.state.user.email) + "&domain=" + encodeURIComponent(this.props.teamName);
} else {
this.state.server_error = err.message;
this.setState(this.state);
@@ -79,7 +79,7 @@ module.exports = React.createClass({
props = {};
props.wizard = "welcome";
props.user = {};
props.user.team_id = this.props.team_id;
props.user.team_id = this.props.teamId;
props.user.email = this.props.email;
props.hash = this.props.hash;
props.data = this.props.data;
@@ -116,7 +116,10 @@ module.exports = React.createClass({
<div>
<img className="signup-team-logo" src="/static/images/logo.png" />
<h4>Welcome to { config.SiteName }</h4>
<p>{"Choose your username and password for the " + this.props.team_name + " " + strings.Team +"."}</p>
<div className="form-group form-group--small">
<span></span>
</div>
<p>{"Choose your username and password for the " + this.props.teamDisplayName + " " + strings.Team} <a href={"/"+this.props.teamName+"/signup/gitlab"}>{"or sign up with GitLab."}</a></p>
<p>Your username can be made of lowercase letters and numbers.</p>
<label className="control-label">Username</label>
<div className={ name_error ? "form-group has-error" : "form-group" }>
+3 -3
View File
@@ -33,7 +33,7 @@ module.exports = React.createClass({
client.createUser(user, "", "",
function(data) {
client.track('signup', 'signup_user_oauth_02');
window.location.href = '/login/'+user.auth_service+'?id='+user.team_id;
window.location.href = '/' + this.props.teamName + '/login/'+user.auth_service;
}.bind(this),
function(err) {
this.state.server_error = err.message;
@@ -63,14 +63,14 @@ module.exports = React.createClass({
<div>
<img className="signup-team-logo" src="/static/images/logo.png" />
<h4>Welcome to { config.SiteName }</h4>
<p>{"To continue signing up with " + this.state.user.auth_type + ", please register a username."}</p>
<p>{"To continue signing up with " + this.state.user.auth_service + ", please register a username."}</p>
<p>Your username can be made of lowercase letters and numbers.</p>
<label className="control-label">Username</label>
<div className={ name_error ? "form-group has-error" : "form-group" }>
<input type="text" ref="name" className="form-control" placeholder="" maxLength="128" value={this.state.user.username} onChange={this.handleChange} />
{ name_error }
</div>
<p>{"Pick something " + strings.Team + "mates will recognize. Your username is how you will appear to others"}</p>
<p>{"Pick something " + strings.Team + "mates will recognize. Your username is how you will appear to others."}</p>
<p>{ yourEmailIs } Youll use this address to sign in to {config.SiteName}.</p>
<div className="checkbox"><label><input type="checkbox" ref="email_service" /> It's ok to send me occassional email with updates about the {config.SiteName} service. </label></div>
<p><button onClick={this.handleSubmit} className="btn-primary btn">Create Account</button></p>
+3 -3
View File
@@ -3,9 +3,9 @@
var SignupUserComplete =require('../components/signup_user_complete.jsx');
global.window.setup_signup_user_complete_page = function(email, domain, name, id, data, hash) {
global.window.setup_signup_user_complete_page = function(email, name, ui_name, id, data, hash) {
React.render(
<SignupUserComplete team_id={id} domain={domain} team_name={name} email={email} hash={hash} data={data} />,
<SignupUserComplete teamId={id} teamName={name} teamDisplayName={ui_name} email={email} hash={hash} data={data} />,
document.getElementById('signup-user-complete')
);
};
};
+2 -2
View File
@@ -3,9 +3,9 @@
var SignupUserOAuth = require('../components/signup_user_oauth.jsx');
global.window.setup_signup_user_oauth_page = function(user) {
global.window.setup_signup_user_oauth_page = function(user, team_name, team_display_name) {
React.render(
<SignupUserOAuth user={user} />,
<SignupUserOAuth user={user} teamName={team_name} teamDisplayName={team_display_name} />,
document.getElementById('signup-user-complete')
);
};
+1 -1
View File
@@ -19,7 +19,7 @@
</div>
</div>
<script>
window.setup_signup_user_oauth_page('{{.Props.User}}');
window.setup_signup_user_oauth_page('{{.Props.User}}', '{{.Props.TeamName}}', '{{.Props.TeamDisplayName}}');
</script>
</body>
</html>
+25 -14
View File
@@ -53,7 +53,8 @@ func InitWeb() {
mainrouter.Handle("/{team:[A-Za-z0-9-]+(__)?[A-Za-z0-9-]+}/", api.AppHandler(login)).Methods("GET")
mainrouter.Handle("/{team:[A-Za-z0-9-]+(__)?[A-Za-z0-9-]+}/login", api.AppHandler(login)).Methods("GET")
mainrouter.Handle("/login/{service:[A-Za-z]+}", api.AppHandlerIndependent(loginWithOAuth)).Methods("GET")
// Bug in gorilla.mux pervents us from using regex here.
mainrouter.Handle("/{team}/login/{service}", api.AppHandler(loginWithOAuth)).Methods("GET")
mainrouter.Handle("/login/{service:[A-Za-z]+}/complete", api.AppHandlerIndependent(loginCompleteOAuth)).Methods("GET")
mainrouter.Handle("/{team:[A-Za-z0-9-]+(__)?[A-Za-z0-9-]+}/logout", api.AppHandler(logout)).Methods("GET")
@@ -66,7 +67,8 @@ func InitWeb() {
mainrouter.Handle("/signup_user_complete/", api.AppHandlerIndependent(signupUserComplete)).Methods("GET")
mainrouter.Handle("/signup_team_confirm/", api.AppHandlerIndependent(signupTeamConfirm)).Methods("GET")
mainrouter.Handle("/signup/{service:[A-Za-z]+}", api.AppHandlerIndependent(signupWithOAuth)).Methods("GET")
// Bug in gorilla.mux pervents us from using regex here.
mainrouter.Handle("/{team}/signup/{service}", api.AppHandler(signupWithOAuth)).Methods("GET")
mainrouter.Handle("/signup/{service:[A-Za-z]+}/complete", api.AppHandlerIndependent(signupCompleteOAuth)).Methods("GET")
mainrouter.Handle("/verify_email", api.AppHandlerIndependent(verifyEmail)).Methods("GET")
@@ -463,20 +465,23 @@ func signupCompleteOAuth(c *api.Context, w http.ResponseWriter, r *http.Request)
code := r.URL.Query().Get("code")
state := r.URL.Query().Get("state")
teamId := r.FormValue("id")
teamName := r.FormValue("team")
uri := c.GetSiteURL() + "/signup/" + service + "/complete?id=" + teamId
uri := c.GetSiteURL() + "/signup/" + service + "/complete?team=" + teamName
if len(teamId) != 26 {
c.Err = model.NewAppError("signupCompleteOAuth", "Invalid team id", "team_id="+teamId)
if len(teamName) == 0 {
c.Err = model.NewAppError("signupCompleteOAuth", "Invalid team name", "team_name="+teamName)
c.Err.StatusCode = http.StatusBadRequest
return
}
// Make sure team exists
if result := <-api.Srv.Store.Team().Get(teamId); result.Err != nil {
var team *model.Team
if result := <-api.Srv.Store.Team().GetByName(teamName); result.Err != nil {
c.Err = result.Err
return
} else {
team = result.Data.(*model.Team)
}
if body, err := api.AuthorizeOAuthUser(service, code, state, uri); err != nil {
@@ -494,10 +499,12 @@ func signupCompleteOAuth(c *api.Context, w http.ResponseWriter, r *http.Request)
return
}
user.TeamId = teamId
user.TeamId = team.Id
page := NewHtmlTemplatePage("signup_user_oauth", "Complete User Sign Up")
page.Props["User"] = user.ToJson()
page.Props["TeamName"] = team.Name
page.Props["TeamDisplayName"] = team.DisplayName
page.Render(c, w)
}
}
@@ -505,6 +512,7 @@ func signupCompleteOAuth(c *api.Context, w http.ResponseWriter, r *http.Request)
func loginWithOAuth(c *api.Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
service := params["service"]
l4g.Debug(service)
redirectUri := c.GetSiteURL() + "/login/" + service + "/complete"
@@ -517,20 +525,23 @@ func loginCompleteOAuth(c *api.Context, w http.ResponseWriter, r *http.Request)
code := r.URL.Query().Get("code")
state := r.URL.Query().Get("state")
teamId := r.FormValue("id")
teamName := r.FormValue("team")
uri := c.GetSiteURL() + "/login/" + service + "/complete?id=" + teamId
uri := c.GetSiteURL() + "/login/" + service + "/complete?team=" + teamName
if len(teamId) != 26 {
c.Err = model.NewAppError("loginCompleteOAuth", "Invalid team id", "team_id="+teamId)
if len(teamName) == 0 {
c.Err = model.NewAppError("loginCompleteOAuth", "Invalid team name", "team_name="+teamName)
c.Err.StatusCode = http.StatusBadRequest
return
}
// Make sure team exists
if result := <-api.Srv.Store.Team().Get(teamId); result.Err != nil {
var team *model.Team
if result := <-api.Srv.Store.Team().GetByName(teamName); result.Err != nil {
c.Err = result.Err
return
} else {
team = result.Data.(*model.Team)
}
if body, err := api.AuthorizeOAuthUser(service, code, state, uri); err != nil {
@@ -549,7 +560,7 @@ func loginCompleteOAuth(c *api.Context, w http.ResponseWriter, r *http.Request)
}
var user *model.User
if result := <-api.Srv.Store.User().GetByAuth(teamId, authData, service); result.Err != nil {
if result := <-api.Srv.Store.User().GetByAuth(team.Id, authData, service); result.Err != nil {
c.Err = result.Err
return
} else {