First time creating a user.
(u *UserRecord)
| 402 | |
| 403 | // First time creating a user. |
| 404 | func 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 | |
| 430 | func LoadUserById(userId int) (*UserRecord, error) { |
| 431 |
no test coverage detected