MCPcopy
hub / github.com/writefreely/writefreely / GetUserForAuth

Method GetUserForAuth

database.go:411–432  ·  view source on GitHub ↗
(username string)

Source from the content-addressed store, hash-verified

409}
410
411func (db *datastore) GetUserForAuth(username string) (*User, error) {
412 u := &User{Username: username}
413
414 err := db.QueryRow("SELECT id, password, email, created, status FROM users WHERE username = ?", username).Scan(&u.ID, &u.HashedPass, &u.Email, &u.Created, &u.Status)
415 switch {
416 case err == sql.ErrNoRows:
417 // Check if they've entered the wrong, unnormalized username
418 username = getSlug(username, "")
419 if username != u.Username {
420 err = db.QueryRow("SELECT id FROM users WHERE username = ? LIMIT 1", username).Scan(&u.ID)
421 if err == nil {
422 return db.GetUserForAuth(username)
423 }
424 }
425 return nil, ErrUserNotFound
426 case err != nil:
427 log.Error("Couldn't SELECT user password: %v", err)
428 return nil, err
429 }
430
431 return u, nil
432}
433
434func (db *datastore) GetUserForAuthByID(userID int64) (*User, error) {
435 u := &User{ID: userID}

Callers

nothing calls this directly

Calls 1

getSlugFunction · 0.85

Tested by

no test coverage detected