MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / CreateUser

Function CreateUser

internal/users/users.go:404–428  ·  view source on GitHub ↗

First time creating a user.

(u *UserRecord)

Source from the content-addressed store, hash-verified

402
403// First time creating a user.
404func CreateUser(u *UserRecord) error {
405
406 if err := ValidateName(u.Username); err != nil {
407 return errors.New("that username is not allowed: " + err.Error())
408 }
409
410 u.UserId = GetUniqueUserId()
411 u.Role = RoleUser
412
413 idx := GetUserIndex()
414 idx.AddUser(u.UserId, u.Username)
415
416 if err := SaveUser(*u); err != nil {
417 return err
418 }
419
420 userManagerMu.Lock()
421 userManager.Users[u.UserId] = u
422 userManager.Usernames[u.Username] = u.UserId
423 userManager.Connections[u.connectionId] = u.UserId
424 userManager.UserConnections[u.UserId] = u.connectionId
425 userManagerMu.Unlock()
426
427 return nil
428}
429
430func LoadUserById(userId int) (*UserRecord, error) {
431

Callers 2

FinalizeLoginOrCreateFunction · 0.92
apiV1CreateUserFunction · 0.92

Calls 8

ValidateNameFunction · 0.85
GetUniqueUserIdFunction · 0.85
GetUserIndexFunction · 0.85
SaveUserFunction · 0.85
NewMethod · 0.80
AddUserMethod · 0.80
LockMethod · 0.80
UnlockMethod · 0.80

Tested by

no test coverage detected