|
|
@ -168,6 +168,11 @@ func DeleteUser(user *User) error { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Delete user directory.
|
|
|
|
|
|
|
|
if err = os.RemoveAll(UserPath(user.Name)); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_, err = orm.Delete(user) |
|
|
|
_, err = orm.Delete(user) |
|
|
|
// TODO: delete and update follower information.
|
|
|
|
// TODO: delete and update follower information.
|
|
|
|
return err |
|
|
|
return err |
|
|
@ -175,8 +180,8 @@ func DeleteUser(user *User) error { |
|
|
|
|
|
|
|
|
|
|
|
// EncodePasswd encodes password to safe format.
|
|
|
|
// EncodePasswd encodes password to safe format.
|
|
|
|
func (user *User) EncodePasswd() error { |
|
|
|
func (user *User) EncodePasswd() error { |
|
|
|
var err error |
|
|
|
newPasswd, err := scrypt.Key([]byte(user.Passwd), []byte(UserPasswdSalt), 16384, 8, 1, 64) |
|
|
|
user.Passwd, err = EncodePasswd(user.Passwd) |
|
|
|
user.Passwd = fmt.Sprintf("%x", newPasswd) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -184,14 +189,6 @@ func UserPath(userName string) string { |
|
|
|
return filepath.Join(RepoRootPath, userName) |
|
|
|
return filepath.Join(RepoRootPath, userName) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func EncodePasswd(rawPasswd string) (string, error) { |
|
|
|
|
|
|
|
newPasswd, err := scrypt.Key([]byte(rawPasswd), []byte(UserPasswdSalt), 16384, 8, 1, 64) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return "", err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return fmt.Sprintf("%x", newPasswd), nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GetUserByKeyId(keyId int64) (*User, error) { |
|
|
|
func GetUserByKeyId(keyId int64) (*User, error) { |
|
|
|
user := new(User) |
|
|
|
user := new(User) |
|
|
|
has, err := orm.Sql("select a.* from user as a, public_key as b where a.id = b.owner_id and b.id=?", keyId).Get(user) |
|
|
|
has, err := orm.Sql("select a.* from user as a, public_key as b where a.id = b.owner_id and b.id=?", keyId).Get(user) |
|
|
|