mirror of https://github.com/writeas/writefreely
Merge pull request #777 from writefreely/reset-password
Support resetting password via email Closes T508pull/785/head
commit
e3323d11c8
@ -0,0 +1,37 @@ |
||||
/* |
||||
* Copyright © 2023 Musing Studio LLC. |
||||
* |
||||
* This file is part of WriteFreely. |
||||
* |
||||
* WriteFreely is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, included |
||||
* in the LICENSE file in this source code package. |
||||
*/ |
||||
|
||||
package migrations |
||||
|
||||
func supportPassReset(db *datastore) error { |
||||
t, err := db.Begin() |
||||
if err != nil { |
||||
t.Rollback() |
||||
return err |
||||
} |
||||
|
||||
_, err = t.Exec(`CREATE TABLE password_resets ( |
||||
user_id ` + db.typeInt() + ` not null, |
||||
token ` + db.typeChar(32) + ` not null primary key, |
||||
used ` + db.typeBool() + ` default 0 not null, |
||||
created ` + db.typeDateTime() + ` not null |
||||
)`) |
||||
if err != nil { |
||||
t.Rollback() |
||||
return err |
||||
} |
||||
|
||||
err = t.Commit() |
||||
if err != nil { |
||||
t.Rollback() |
||||
return err |
||||
} |
||||
return nil |
||||
} |
@ -0,0 +1,58 @@ |
||||
{{define "head"}}<title>Reset password — {{.SiteName}}</title> |
||||
<style> |
||||
input { |
||||
margin-bottom: 0.5em; |
||||
width: 100%; |
||||
box-sizing: border-box; |
||||
} |
||||
label { |
||||
display: block; |
||||
} |
||||
</style> |
||||
{{end}} |
||||
{{define "content"}} |
||||
<div class="toosmall content-container clean"> |
||||
<h1>Reset your password</h1> |
||||
|
||||
{{ if .DisablePasswordAuth }} |
||||
<div class="alert info"> |
||||
<p><strong>Password login is disabled on this server</strong>, so it's not possible to reset your password.</p> |
||||
</div> |
||||
{{ else if not .EmailEnabled }} |
||||
<div class="alert info"> |
||||
<p><strong>Email is not configured on this server!</strong> Please <a href="/contact">contact your admin</a> to reset your password.</p> |
||||
</div> |
||||
{{ else }} |
||||
{{if .Flashes}}<ul class="errors"> |
||||
{{range .Flashes}}<li class="urgent">{{.}}</li>{{end}} |
||||
</ul>{{end}} |
||||
|
||||
{{if .IsResetting}} |
||||
<form method="post" action="/reset" onsubmit="disableSubmit()"> |
||||
<label> |
||||
<p>New Password</p> |
||||
<input type="password" name="new-pass" autocomplete="new-password" placeholder="New password" tabindex="1" /> |
||||
</label> |
||||
<input type="hidden" name="t" value="{{.Token}}" /> |
||||
<input type="submit" id="btn-login" value="Reset Password" /> |
||||
{{ .CSRFField }} |
||||
</form> |
||||
{{else if not .IsSent}} |
||||
<form action="/reset" method="post" onsubmit="disableSubmit()"> |
||||
<label> |
||||
<p>Username</p> |
||||
<input type="text" name="alias" placeholder="Username" autofocus /> |
||||
</label> |
||||
{{ .CSRFField }} |
||||
<input type="submit" id="btn-login" value="Reset Password" /> |
||||
</form> |
||||
{{end}} |
||||
|
||||
<script type="text/javascript"> |
||||
var $btn = document.getElementById("btn-login"); |
||||
function disableSubmit() { |
||||
$btn.disabled = true; |
||||
} |
||||
</script> |
||||
{{ end }} |
||||
{{end}} |
@ -0,0 +1,25 @@ |
||||
/* |
||||
* Copyright © 2023 Musing Studio LLC. |
||||
* |
||||
* This file is part of WriteFreely. |
||||
* |
||||
* WriteFreely is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License, included |
||||
* in the LICENSE file in this source code package. |
||||
*/ |
||||
|
||||
package spam |
||||
|
||||
import ( |
||||
"net/http" |
||||
"strings" |
||||
) |
||||
|
||||
func GetIP(r *http.Request) string { |
||||
h := r.Header.Get("X-Forwarded-For") |
||||
if h == "" { |
||||
return "" |
||||
} |
||||
ips := strings.Split(h, ",") |
||||
return strings.TrimSpace(ips[0]) |
||||
} |
Loading…
Reference in new issue