Compare commits
No commits in common. "0603386f4cdbeee827f535d140a91fabd7c58083" and "4494932246cfea120ea0158a14584c539353ad1e" have entirely different histories.
0603386f4c
...
4494932246
|
|
@ -2,27 +2,5 @@ BEGIN TRANSACTION;
|
||||||
|
|
||||||
ALTER TABLE gift RENAME TO wish;
|
ALTER TABLE gift RENAME TO wish;
|
||||||
|
|
||||||
ALTER TABLE user ADD COLUMN display_name TEXT NOT NULL DEFAULT "";
|
|
||||||
|
|
||||||
UPDATE user SET display_name = name;
|
|
||||||
|
|
||||||
ALTER TABLE user RENAME TO old_user;
|
|
||||||
|
|
||||||
CREATE TABLE "user" (
|
|
||||||
"id" INTEGER NOT NULL UNIQUE,
|
|
||||||
"name" TEXT NOT NULL UNIQUE,
|
|
||||||
"display_name" TEXT NOT NULL UNIQUE,
|
|
||||||
"reference" TEXT NOT NULL UNIQUE,
|
|
||||||
"motto" TEXT NOT NULL DEFAULT "",
|
|
||||||
"password_hash" TEXT NOT NULL,
|
|
||||||
"is_admin" INTEGER NOT NULL DEFAULT 0,
|
|
||||||
"is_live" INTEGER NOT NULL DEFAULT 1,
|
|
||||||
PRIMARY KEY("id" AUTOINCREMENT)
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO user (id, name, display_name, reference, motto, password_hash, is_admin, is_live) SELECT id, name, name, reference, motto, password_hash, is_admin, is_live FROM old_user;
|
|
||||||
|
|
||||||
DROP TABLE "old_user";
|
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"__meta__": {
|
||||||
|
"about": "xh session file",
|
||||||
|
"xh": "0.24.1"
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": null,
|
||||||
|
"raw_auth": null
|
||||||
|
},
|
||||||
|
"cookies": [
|
||||||
|
{
|
||||||
|
"name": "lishwist_user",
|
||||||
|
"value": "MTc1MDg2NDE2N3xCQXdBQVRjPXw8gaasdVy--TC-_fUb-3ZL58n8UVakTqDm_0_7c50cYA==",
|
||||||
|
"expires": 1750950567,
|
||||||
|
"path": "/lists",
|
||||||
|
"domain": "127.0.0.1"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"headers": []
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
lishwist "lishwist/core"
|
||||||
"lishwist/http/templates"
|
"lishwist/http/templates"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -40,3 +43,30 @@ func (p *LoginProps) Validate() (valid bool) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Login(username, password string) *LoginProps {
|
||||||
|
props := NewLoginProps(username, password)
|
||||||
|
|
||||||
|
valid := props.Validate()
|
||||||
|
props.Password.Value = ""
|
||||||
|
if !valid {
|
||||||
|
log.Printf("Invalid props: %#v\n", props)
|
||||||
|
return props
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := lishwist.Login(props.Username.Value, props.Password.Value)
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
switch err.(type) {
|
||||||
|
case lishwist.ErrorInvalidCredentials:
|
||||||
|
log.Printf("Invalid credentials: %w\n", err)
|
||||||
|
props.GeneralError = "Username or password invalid"
|
||||||
|
return props
|
||||||
|
default:
|
||||||
|
log.Printf("Login error: %w\n", err)
|
||||||
|
props.GeneralError = "Something went wrong."
|
||||||
|
return props
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
passwordHash := []byte(os.Args[1])
|
|
||||||
password := []byte(os.Args[2])
|
|
||||||
err := bcrypt.CompareHashAndPassword(passwordHash, password)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln("Failed to match: ", err)
|
|
||||||
}
|
|
||||||
fmt.Println("Match!")
|
|
||||||
}
|
|
||||||
|
|
@ -53,7 +53,7 @@ func LoginPost(h http.Header, r *rsvp.Request) rsvp.Response {
|
||||||
case lishwist.ErrorInvalidCredentials:
|
case lishwist.ErrorInvalidCredentials:
|
||||||
props.GeneralError = "Username or password invalid"
|
props.GeneralError = "Username or password invalid"
|
||||||
session.FlashSet(&props)
|
session.FlashSet(&props)
|
||||||
return rsvp.SeeOther("/").SaveSession(session).Log("Invalid credentials: %s: %#v\n", err, props)
|
return rsvp.SeeOther("/").SaveSession(session).Log("Invalid credentials: %#v\n", props)
|
||||||
default:
|
default:
|
||||||
props.GeneralError = "Something went wrong."
|
props.GeneralError = "Something went wrong."
|
||||||
session.FlashSet(&props)
|
session.FlashSet(&props)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue