Ejemplo n.º 1
0
        public object UserChangePassword(string userName, [FromBody] AuthorizedChange authorizedChange)
        {
            if (!authorizedChange.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, @"Invalid payload"));
            }

            var user = Database.PlayerData.User.Find(userName);

            if (user == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $@"No user with name '{userName}'."));
            }

            if (!user.TryChangePassword(
                    authorizedChange.Authorization.ToUpper().Trim(), authorizedChange.New.ToUpper().Trim()
                    ))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, @"Invalid credentials."));
            }

            DbInterface.SavePlayerDatabaseAsync();

            return(Request.CreateMessageResponse(HttpStatusCode.OK, "Password Updated."));
        }
Ejemplo n.º 2
0
        public object UserChangePassword(Guid userId, [FromBody] AuthorizedChange authorizedChange)
        {
            if (!authorizedChange.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, @"Invalid payload"));
            }

            var user = Database.PlayerData.User.Find(userId);

            if (user == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $@"No user with name '{userId}'."));
            }

            if (!user.TryChangePassword(
                    authorizedChange.Authorization.ToUpper().Trim(), authorizedChange.New.ToUpper().Trim()
                    ))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, @"Invalid credentials."));
            }

            user.Save();

            return("Password updated.");
        }
Ejemplo n.º 3
0
        public object UserChangeEmailById(Guid userId, [FromBody] AuthorizedChange authorizedChange)
        {
            var email = authorizedChange.New;

            if (string.IsNullOrWhiteSpace(email))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, $@"Malformed email address '{email}'."));
            }

            if (!FieldChecking.IsWellformedEmailAddress(email, Strings.Regex.email))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, $@"Malformed email address '{email}'."));
            }

            var user = Database.PlayerData.User.Find(userId);

            if (user == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, $@"No user with id '{userId}'."));
            }

            if (!user.IsPasswordValid(authorizedChange.Authorization.ToUpper().Trim()))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, @"Invalid credentials."));
            }

            if (DbInterface.EmailInUse(email))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, @"Email address already in use."));
            }

            user.Email = email;

            DbInterface.SavePlayerDatabaseAsync();

            return(user);
        }