Example #1
0
        public object UserChangeEmailById(Guid userId, [FromBody] AdminChange 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 (Database.PlayerData.User.UserExists(email))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, @"Email address already in use."));
            }

            user.Email = email;
            user.Save();

            return(user);
        }
        public bool ChangePassword(AdminChange content)
        {
            Users user = this.database.Users.Where(u => u.Username == content.Username).First <Users>();

            if (BCrypt.Net.BCrypt.Verify(content.Password, user.Password)) //missing Bcrypt ==>  BCrypt.Net.BCrypt.Verify(content.Password,user.Password))
            {
                user.Password = content.Password;
                this.database.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        public static void WriteAdminChange(string description)
        {
            if (!CurrentMisparIshi.IsAdmin())
            {
                return;
            }
            var message = String.Format(
                "The admin {0} made the following change: {1}.",
                CurrentMisparIshi.GetCurrentMisparIshi(),
                description);
            var newAdminChange = new AdminChange();

            newAdminChange.Description = message;
            newAdminChange.TimeAdded   = DateTime.Now;
            var dataContext = new LogDataContext();

            dataContext.AdminChanges.InsertOnSubmit(newAdminChange);
            dataContext.SubmitChanges();
        }
Example #4
0
        public object UserChangePassword(Guid userId, [FromBody] AdminChange 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.TrySetPassword(authorizedChange.New.ToUpper().Trim()))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, @"Failed to update password."));
            }

            user.Save();

            return(Request.CreateMessageResponse(HttpStatusCode.OK, "Password Updated."));
        }
Example #5
0
        public object UserChangePassword(string userName, [FromBody] AdminChange 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.TrySetPassword(authorizedChange.New.ToUpper().Trim()))
            {
                return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, @"Failed to update password."));
            }

            DbInterface.SavePlayerDatabaseAsync();

            return("Password updated.");
        }