added code to prevent panic if /login is reached but no settings exist
minor styling. added success and fail message to top of /signup screen modified open_registration to boolean value in database
This commit is contained in:
parent
a699e6ef09
commit
4b412d3a26
7 changed files with 38 additions and 25 deletions
|
@ -49,7 +49,7 @@ insert into builds values (9, 3, 'node_0.80', 'Success', '2013-09-16 00:00:00','
|
|||
|
||||
-- insert default, dummy settings
|
||||
|
||||
insert into settings values (1,'','','','','','','','','','localhost:8080','http');
|
||||
insert into settings values (1,'','','','','','','','','','localhost:8080','http', 0);
|
||||
|
||||
-- add public & private keys to all repositories
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ CREATE TABLE settings (
|
|||
,smtp_password VARCHAR(1024)
|
||||
,hostname VARCHAR(1024)
|
||||
,scheme VARCHAR(5)
|
||||
,open_invitations INTEGER
|
||||
,open_invitations BOOLEAN
|
||||
);
|
||||
`
|
||||
|
||||
|
@ -195,5 +195,9 @@ func Load(db *sql.DB) error {
|
|||
db.Exec(buildCommitIndex)
|
||||
db.Exec(buildSlugIndex)
|
||||
|
||||
// migrations for backward compatibility
|
||||
db.Exec("ALTER TABLE settings ADD COLUMN open_invitations BOOLEAN")
|
||||
db.Exec("UPDATE settings SET open_invitations=0 WHERE open_invitations IS NULL")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ CREATE TABLE settings (
|
|||
,smtp_password VARCHAR(1024)
|
||||
,hostname VARCHAR(1024)
|
||||
,scheme VARCHAR(5)
|
||||
,open_invitations INTEGER
|
||||
,open_invitations BOOLEAN
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX member_uix ON members (team_id, user_id);
|
||||
|
|
|
@ -2,7 +2,6 @@ package handler
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
@ -56,11 +55,7 @@ func UserInvite(w http.ResponseWriter, r *http.Request) error {
|
|||
}{hostname, email, token}
|
||||
|
||||
// send the email message async
|
||||
go func() {
|
||||
if err := mail.SendActivation(email, data); err != nil {
|
||||
log.Printf("error sending account activation email to %s. %s", email, err)
|
||||
}
|
||||
}()
|
||||
go mail.SendActivation(email, data)
|
||||
|
||||
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
|
||||
}
|
||||
|
|
|
@ -163,12 +163,31 @@ func ResetPost(w http.ResponseWriter, r *http.Request) error {
|
|||
}
|
||||
|
||||
func SignUpPost(w http.ResponseWriter, r *http.Request) error {
|
||||
// if self-registration is disabled we should display an
|
||||
// error message to the user.
|
||||
if !database.SettingsMust().OpenInvitations {
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
|
||||
return nil
|
||||
}
|
||||
|
||||
return UserInvite(w, r)
|
||||
// generate the password reset token
|
||||
email := r.FormValue("email")
|
||||
token := authcookie.New(email, time.Now().Add(12*time.Hour), secret)
|
||||
|
||||
// get the hostname from the database for use in the email
|
||||
hostname := database.SettingsMust().URL().String()
|
||||
|
||||
// data used to generate the email template
|
||||
data := struct {
|
||||
Host string
|
||||
Email string
|
||||
Token string
|
||||
}{hostname, email, token}
|
||||
|
||||
// send the email message async
|
||||
go mail.SendActivation(email, data)
|
||||
|
||||
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
|
||||
}
|
||||
|
||||
func RegisterPost(w http.ResponseWriter, r *http.Request) error {
|
||||
|
|
|
@ -10,10 +10,11 @@
|
|||
<input type="submit" value="Sign in" />
|
||||
</div>
|
||||
<div>
|
||||
{{ if .Settings ne nil and .Settings.OpenInvitations }}
|
||||
<a href="/signup">request invitation</a> ·
|
||||
{{ end }}
|
||||
{{ if .Settings }}
|
||||
<a href="/signup">request invitation</a> | <a href="/forgot">forgot password</a>
|
||||
{{ else }}
|
||||
<a href="/forgot">forgot password</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
|
|
|
@ -3,15 +3,13 @@
|
|||
{{ define "content" }}
|
||||
<h1>Sign up</h1>
|
||||
<form action="/signup" method="POST" role="form">
|
||||
<div class="alert alert-success hide" id="successAlert"></div>
|
||||
<div class="alert alert-error hide" id="failureAlert"></div>
|
||||
<div>
|
||||
<input type="text" name="email" placeholder="Email address" autocomplete="off" spellcheck="false" class="form-control only-child" />
|
||||
</div>
|
||||
<div>
|
||||
<div class="alert alert-success hide" id="successAlert"></div>
|
||||
<div class="alert alert-error hide" id="failureAlert"></div>
|
||||
</div>
|
||||
<div>
|
||||
<input type="submit" id="submitButton" value="Request invite" />
|
||||
<input type="submit" id="submitButton" value="Request invite" data-loading-text="Sending Invite .." />
|
||||
</div>
|
||||
</form>
|
||||
{{ end }}
|
||||
|
@ -30,11 +28,7 @@
|
|||
xhr.open('POST', form.action);
|
||||
xhr.onload = function() {
|
||||
if (this.status == 200) {
|
||||
var msg = "User Invitation was sent successfully";
|
||||
if (this.responseText != "OK") {
|
||||
msg = "Email is not currently enables. Follow the link:<br><a href='" + this.responseText + "'>" + this.responseText + "</a>";
|
||||
}
|
||||
$("#successAlert").html(msg);
|
||||
$("#successAlert").text("User Invitation was sent successfully");
|
||||
$("#successAlert").show().removeClass("hide");
|
||||
$('#submitButton').button('reset')
|
||||
|
||||
|
@ -46,6 +40,6 @@
|
|||
};
|
||||
xhr.send(formData);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{{ end }}
|
Loading…
Reference in a new issue