Пример #1
0
        public IActionResult Signup(string username)
        {
            //todo better validation
            if (username == null)
            {
                return(BadRequest("Username not provided"));
            }
            lock (_users)
            {
                var userMetaFromRequest = GetUserRequestMeta();

                if (userMetaFromRequest.isSignedIn)
                {
                    return(BadRequest("User already signed in"));
                }
                else if (_users.DoesUsernameExist(username))
                {
                    return(BadRequest("Username in use"));
                }
                else
                {
                    var id = userMetaFromRequest.profile.Id;

                    var newUser = new User {
                        Username = username,
                        Id       = id
                    };

                    _users.Set(id, newUser);

                    return(Ok(username));
                }
            }
        }