Skip to content

Commit

Permalink
fix legacy password and signup redirect (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
uberswe authored Feb 15, 2025
1 parent 2c5862b commit 0cd90d7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
12 changes: 1 addition & 11 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/pocketbase/pocketbase/tools/mailer"
"github.com/sunshineplan/imgconv"
"github.com/sym01/htmlsanitizer"
"golang.org/x/crypto/bcrypt"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"log"
Expand Down Expand Up @@ -231,17 +230,8 @@ func (s *Server) Start() {
if e.Record != nil && e.Record.GetString("old_password") != "" {
p := phpass.New(nil)
if p.Check([]byte(e.Password), []byte(e.Record.GetString("old_password"))) {
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(e.Password), 12)
if err != nil {
s.app.Logger().Warn("old password failled to hash", "error", err.Error())
return e.Next()
}
e.Record.SetPassword(string(hashedPassword))
e.Record.SetPassword(e.Password)
e.Record.Set("old_password", "")
if err = s.app.Save(e.Record); err != nil {
s.app.Logger().Warn("old password invalid", "error", err.Error())
return e.Next()
}
}
}
return e.Next()
Expand Down
7 changes: 7 additions & 0 deletions template/include/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@
pb.collection('users').requestVerification(email.value);
let successModal = new bootstrap.Modal(document.getElementById('modal-success'), {});
successModal.show();
// Log the user in automatically
pb.collection('users').authWithPassword(
username.value,
password.value,
).then((authData) => {
location.href = '/'
});
}).catch((e) => {
if (e.data === undefined || e.data.data === undefined) {
alert("Something went wrong, please reload the page and try again")
Expand Down
4 changes: 2 additions & 2 deletions template/schematic.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,15 @@ <h3 class="card-title">Comments</h3>
{{ .Created }}
</a>
</div>
{{ if .IsAuthenticated }}
<div class="col-auto">
<a href="#tinymce-comment"
onclick="commentReply('{{ .ID }}', '{{ .Author }}')"
class="link">
Reply
</a>
</div>
{{ end }}
<div class="col-auto">
<a id="{{ .ID }}" href="#{{ .ID }}" class="link-muted">
<!-- Download SVG icon from http://tabler.io/icons/icon/share -->
Expand Down Expand Up @@ -364,7 +366,6 @@ <h3>Similar Schematics</h3>
})
// @formatter:on
</script>
{{ if .IsAuthenticated }}
<script>
document.addEventListener("DOMContentLoaded", function () {
const rating = new StarRating('#rating-default', {
Expand Down Expand Up @@ -408,7 +409,6 @@ <h3>Similar Schematics</h3>
});
})
</script>
{{ end }}
{{ if .IsAuthenticated }}
<script>
function commentReply(id, username) {
Expand Down

0 comments on commit 0cd90d7

Please sign in to comment.