Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Jan 23, 2020
1 parent 7773ba7 commit fd9ee02
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
10 changes: 5 additions & 5 deletions pkg/hypervisor/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func NewSingleUserStore(username string, users UserStore) *SingleUserStore {

// User gets a user.
func (s *SingleUserStore) User(name string) (*User, error) {
if !s.allowName(name) {
if !s.isNameAllowed(name) {
return nil, ErrNameNotAllowed
}

Expand All @@ -206,7 +206,7 @@ func (s *SingleUserStore) User(name string) (*User, error) {

// AddUser adds a new user.
func (s *SingleUserStore) AddUser(user User) error {
if !s.allowName(user.Name) {
if !s.isNameAllowed(user.Name) {
return ErrNameNotAllowed
}

Expand All @@ -215,7 +215,7 @@ func (s *SingleUserStore) AddUser(user User) error {

// SetUser sets an existing user.
func (s *SingleUserStore) SetUser(user User) error {
if !s.allowName(user.Name) {
if !s.isNameAllowed(user.Name) {
return ErrNameNotAllowed
}

Expand All @@ -224,14 +224,14 @@ func (s *SingleUserStore) SetUser(user User) error {

// RemoveUser removes a user.
func (s *SingleUserStore) RemoveUser(name string) error {
if !s.allowName(name) {
if !s.isNameAllowed(name) {
return ErrNameNotAllowed
}

return s.UserStore.RemoveUser(name)
}

func (s *SingleUserStore) allowName(name string) bool {
func (s *SingleUserStore) isNameAllowed(name string) bool {
return name == s.username
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/hypervisor/user_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ func (s *UserManager) Authorize(next http.Handler) http.Handler {
// ChangePassword returns a HandlerFunc for changing the user's password.
func (s *UserManager) ChangePassword() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var user = r.Context().Value(userKey).(User)

var rb struct {
OldPassword string `json:"old_password"`
NewPassword string `json:"new_password"`
Expand All @@ -155,6 +153,7 @@ func (s *UserManager) ChangePassword() http.HandlerFunc {
return
}

user := r.Context().Value(userKey).(User)
if ok := user.VerifyPassword(rb.OldPassword); !ok {
httputil.WriteJSON(w, r, http.StatusUnauthorized, ErrBadLogin)
return
Expand Down

0 comments on commit fd9ee02

Please sign in to comment.