Added ability to add user
This commit is contained in:
@ -35,16 +35,6 @@ func OpenDB(dbName string) (*DB, error) {
|
||||
}
|
||||
|
||||
func (db *DB) AddUser(user, pass, first, last string, writer, editor, admin bool) error {
|
||||
userString, stringLen, ok := checkUserStrings(user, first, last)
|
||||
if !ok {
|
||||
return fmt.Errorf("error: %v is longer than %v characters", userString, stringLen)
|
||||
}
|
||||
|
||||
if !permissionsOK(writer, editor, admin) {
|
||||
return fmt.Errorf("error: permissions must be mutually exclusive: writer = %v, editor = %v, admin = %v",
|
||||
writer, editor, admin)
|
||||
}
|
||||
|
||||
hashedPass, err := bcrypt.GenerateFromPassword([]byte(pass), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating password hash: %v", err)
|
||||
|
@ -50,24 +50,3 @@ func getCredentials() (string, string, error) {
|
||||
|
||||
return user, pass, nil
|
||||
}
|
||||
|
||||
func checkUserStrings(user, first, last string) (string, int, bool) {
|
||||
userLen := 15
|
||||
nameLen := 50
|
||||
|
||||
if len(user) > userLen {
|
||||
return user, userLen, false
|
||||
} else if len(first) > nameLen {
|
||||
return first, nameLen, false
|
||||
} else if len(last) > nameLen {
|
||||
return last, nameLen, false
|
||||
} else {
|
||||
return "", 0, true
|
||||
}
|
||||
}
|
||||
|
||||
func permissionsOK(writer, editor, admin bool) bool {
|
||||
return writer && !editor && !admin ||
|
||||
!writer && editor && !admin ||
|
||||
!writer && !editor && admin
|
||||
}
|
||||
|
Reference in New Issue
Block a user