l10n, create dir on creating file

This commit is contained in:
Wancat
2022-11-04 23:17:17 +08:00
parent 9f99aad680
commit 7c63223aa0
4 changed files with 15 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ import (
) )
type AuthStore interface { type AuthStore interface {
Get(user string) bool
Register(user, pass string) error Register(user, pass string) error
Login(user, pass string) (token string, err error) Login(user, pass string) (token string, err error)
Verify(token string) (session Session, err error) Verify(token string) (session Session, err error)
@@ -39,6 +40,11 @@ func New(path string, hashKey []byte) (AuthStore, error) {
return s, err return s, err
} }
func (s Htpasswd) Get(user string) bool {
_, ok := s.accounts[user]
return ok
}
func (s Htpasswd) Register(user, pass string) (err error) { func (s Htpasswd) Register(user, pass string) (err error) {
if _, ok := s.accounts[user]; ok { if _, ok := s.accounts[user]; ok {
return errors.New("user already exists") return errors.New("user already exists")

View File

@@ -1,10 +1,11 @@
{{ define "title" }}Sign Up{{ end }} {{ define "title" }}登入{{ end }}
{{ define "main" }} {{ define "main" }}
<h1>Sign In</h1> <h1>登入</h1>
<form action="/signin" method="POST"> <form action="/signin" method="POST">
<label>Email: <input type="text" name="email"></label><br> <label>Email: <input type="text" name="email"></label><br>
<label>Password: <input type="password" name="password"></label><br> <label>Password: <input type="password" name="password"></label><br>
{{ with .Error }}<p class="error">{{ . }}</p>{{ end }} {{ with .Error }}<p class="error">{{ . }}</p>{{ end }}
<input type="submit" value="Sign Up"> <input type="submit" value="登入">
</form> </form>
<a href="signup">沒有帳號嗎?註冊</a>
{{ end }} {{ end }}

View File

@@ -1,10 +1,11 @@
{{ define "title" }}Sign Up{{ end }} {{ define "title" }}註冊{{ end }}
{{ define "main" }} {{ define "main" }}
<h1>Sign Up</h1> <h1>註冊</h1>
<form action="/signup" method="POST"> <form action="/signup" method="POST">
<label>Email: <input type="text" name="email"></label><br> <label>Email: <input type="text" name="email"></label><br>
<label>Password: <input type="password" name="password"></label><br> <label>Password: <input type="password" name="password"></label><br>
{{ with .Error }}<p class="error">{{ . }}</p>{{ end }} {{ with .Error }}<p class="error">{{ . }}</p>{{ end }}
<input type="submit" value="Sign Up"> <input type="submit" value="註冊">
</form> </form>
<a href="signin">已有帳號嗎?登入</a>
{{ end }} {{ end }}

View File

@@ -20,7 +20,7 @@ func (u *User) Dir() string {
} }
func (u *User) FilePath(name string) string { func (u *User) FilePath(name string) string {
return path.Join(DATA_DIR, u.Email, name) return path.Join(u.Dir(), name)
} }
func (u *User) File(name string) (*os.File, error) { func (u *User) File(name string) (*os.File, error) {