add suspend and unsuspend calls
This commit is contained in:
parent
b062c4aea1
commit
498f7f7393
35
auth.go
35
auth.go
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
@ -65,3 +66,37 @@ func (u *UserData) ChangePassword(oldpass, newpass string) bool {
|
|||
}
|
||||
return u.SetPassword(newcrypt)
|
||||
}
|
||||
|
||||
func (u *UserData) Suspend() bool {
|
||||
var hash string
|
||||
u.Set("status", "inactive")
|
||||
q := fmt.Sprintf("select password from %s_users where id=? limit 1", c.TablePrefix)
|
||||
err := c.db.Get(&hash, q, u.UserID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if strings.HasPrefix(hash, "*") {
|
||||
return true
|
||||
}
|
||||
newhash := "*" + hash
|
||||
q = fmt.Sprintf("update %s_users set password=? where id=?", c.TablePrefix)
|
||||
_, err = c.db.Exec(q, newhash, u.UserID)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (u *UserData) Unsuspend() bool {
|
||||
var hash string
|
||||
u.Set("status", "active")
|
||||
q := fmt.Sprintf("select password from %s_users where id=? limit 1", c.TablePrefix)
|
||||
err := c.db.Get(&hash, q, u.UserID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if !strings.HasPrefix(hash, "*") {
|
||||
return true
|
||||
}
|
||||
newhash := strings.TrimPrefix(hash, "*")
|
||||
q = fmt.Sprintf("update %s_users set password=? where id=?", c.TablePrefix)
|
||||
_, err = c.db.Exec(q, newhash, u.UserID)
|
||||
return err == nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue