diff --git a/pkg/database/schema/sample.sql b/pkg/database/schema/sample.sql index 6b3f6f297..594caaa3e 100644 --- a/pkg/database/schema/sample.sql +++ b/pkg/database/schema/sample.sql @@ -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 diff --git a/pkg/database/schema/schema.go b/pkg/database/schema/schema.go index a72415183..ec93774a8 100644 --- a/pkg/database/schema/schema.go +++ b/pkg/database/schema/schema.go @@ -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 } diff --git a/pkg/database/schema/schema.sql b/pkg/database/schema/schema.sql index 39cda73a3..d0babf327 100644 --- a/pkg/database/schema/schema.sql +++ b/pkg/database/schema/schema.sql @@ -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); diff --git a/pkg/handler/admin.go b/pkg/handler/admin.go index 1d028f783..3d7fa8b5a 100644 --- a/pkg/handler/admin.go +++ b/pkg/handler/admin.go @@ -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) } diff --git a/pkg/handler/app.go b/pkg/handler/app.go index b0bfb1d18..9d720113c 100644 --- a/pkg/handler/app.go +++ b/pkg/handler/app.go @@ -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 { diff --git a/pkg/template/pages/login.html b/pkg/template/pages/login.html index 8c383b044..4967f119c 100644 --- a/pkg/template/pages/login.html +++ b/pkg/template/pages/login.html @@ -10,10 +10,11 @@