mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
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 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
|
-- add public & private keys to all repositories
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,7 @@ CREATE TABLE settings (
|
||||||
,smtp_password VARCHAR(1024)
|
,smtp_password VARCHAR(1024)
|
||||||
,hostname VARCHAR(1024)
|
,hostname VARCHAR(1024)
|
||||||
,scheme VARCHAR(5)
|
,scheme VARCHAR(5)
|
||||||
,open_invitations INTEGER
|
,open_invitations BOOLEAN
|
||||||
);
|
);
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -195,5 +195,9 @@ func Load(db *sql.DB) error {
|
||||||
db.Exec(buildCommitIndex)
|
db.Exec(buildCommitIndex)
|
||||||
db.Exec(buildSlugIndex)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ CREATE TABLE settings (
|
||||||
,smtp_password VARCHAR(1024)
|
,smtp_password VARCHAR(1024)
|
||||||
,hostname VARCHAR(1024)
|
,hostname VARCHAR(1024)
|
||||||
,scheme VARCHAR(5)
|
,scheme VARCHAR(5)
|
||||||
,open_invitations INTEGER
|
,open_invitations BOOLEAN
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX member_uix ON members (team_id, user_id);
|
CREATE UNIQUE INDEX member_uix ON members (team_id, user_id);
|
||||||
|
|
|
@ -2,7 +2,6 @@ package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
@ -56,11 +55,7 @@ func UserInvite(w http.ResponseWriter, r *http.Request) error {
|
||||||
}{hostname, email, token}
|
}{hostname, email, token}
|
||||||
|
|
||||||
// send the email message async
|
// send the email message async
|
||||||
go func() {
|
go mail.SendActivation(email, data)
|
||||||
if err := mail.SendActivation(email, data); err != nil {
|
|
||||||
log.Printf("error sending account activation email to %s. %s", email, err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
|
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 {
|
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 {
|
if !database.SettingsMust().OpenInvitations {
|
||||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
|
||||||
return nil
|
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 {
|
func RegisterPost(w http.ResponseWriter, r *http.Request) error {
|
||||||
|
|
|
@ -10,10 +10,11 @@
|
||||||
<input type="submit" value="Sign in" />
|
<input type="submit" value="Sign in" />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{{ if .Settings ne nil and .Settings.OpenInvitations }}
|
{{ if .Settings }}
|
||||||
<a href="/signup">request invitation</a> ·
|
<a href="/signup">request invitation</a> | <a href="/forgot">forgot password</a>
|
||||||
{{ end }}
|
{{ else }}
|
||||||
<a href="/forgot">forgot password</a>
|
<a href="/forgot">forgot password</a>
|
||||||
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,13 @@
|
||||||
{{ define "content" }}
|
{{ define "content" }}
|
||||||
<h1>Sign up</h1>
|
<h1>Sign up</h1>
|
||||||
<form action="/signup" method="POST" role="form">
|
<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>
|
<div>
|
||||||
<input type="text" name="email" placeholder="Email address" autocomplete="off" spellcheck="false" class="form-control only-child" />
|
<input type="text" name="email" placeholder="Email address" autocomplete="off" spellcheck="false" class="form-control only-child" />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="alert alert-success hide" id="successAlert"></div>
|
<input type="submit" id="submitButton" value="Request invite" data-loading-text="Sending Invite .." />
|
||||||
<div class="alert alert-error hide" id="failureAlert"></div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<input type="submit" id="submitButton" value="Request invite" />
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -30,11 +28,7 @@
|
||||||
xhr.open('POST', form.action);
|
xhr.open('POST', form.action);
|
||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
if (this.status == 200) {
|
if (this.status == 200) {
|
||||||
var msg = "User Invitation was sent successfully";
|
$("#successAlert").text("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").show().removeClass("hide");
|
$("#successAlert").show().removeClass("hide");
|
||||||
$('#submitButton').button('reset')
|
$('#submitButton').button('reset')
|
||||||
|
|
||||||
|
@ -46,6 +40,6 @@
|
||||||
};
|
};
|
||||||
xhr.send(formData);
|
xhr.send(formData);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
{{ end }}
|
{{ end }}
|
Loading…
Reference in a new issue