Example #1
0
        public IActionResult SetUserConfiguration([FromBody] SetUserConfigurationModel model)
        {
            int id = userIdentity.GetCurrentUser().Result.Id;

            if (ModelState.IsValid)
            {
                if (!String.IsNullOrEmpty(model.Password) &&
                    !String.IsNullOrWhiteSpace(model.Password) &&
                    (!String.IsNullOrEmpty(model.NewPassword) &&
                     !String.IsNullOrWhiteSpace(model.NewPassword)) &&
                    (!String.IsNullOrEmpty(model.NewPasswordConfirmation) &&
                     !String.IsNullOrWhiteSpace(model.NewPasswordConfirmation)))
                {
                    using (var managementClient = new ManagementApiClient())
                    {
                        if (managementClient.AuthenticateUser(model.Email, model.Password).StatusCode == HttpStatusCode.OK)
                        {
                            if (model.NewPassword == model.NewPasswordConfirmation)
                            {
                                if (managementClient.EditUsersPassword(model.Email, model.NewPassword).StatusCode != HttpStatusCode.OK)
                                {
                                    return(new StatusCodeResult(503));
                                }
                            }
                            else
                            {
                                return(new StatusCodeResult(400));
                            }
                        }
                        else
                        {
                            return(new StatusCodeResult(403));
                        }
                    }
                }
                var result = ds.EditUsername(id, model.Username);

                switch (result)
                {
                case ObjectManipulationResult.Success:
                    return(new StatusCodeResult(200));

                case ObjectManipulationResult.Exists:
                    return(new StatusCodeResult(409));

                case ObjectManipulationResult.ErrorOccured:
                    return(new StatusCodeResult(500));

                default:
                    return(new StatusCodeResult(500));
                }
            }
            else
            {
                return(new StatusCodeResult(400));
            }
        }
Example #2
0
        public IActionResult SetUserPassword([FromBody] UserCredentialsModel model)
        {
            if (ModelState.IsValid)
            {
                if (!String.IsNullOrEmpty(model.Password) &&
                    !String.IsNullOrWhiteSpace(model.Password))
                {
                    User user = ds.GetUserByEmail(model.Email);

                    if (user != null)
                    {
                        if (!user.IsPasswordSet)
                        {
                            using (var managementClient = new ManagementApiClient())
                            {
                                try
                                {
                                    managementClient.EditUsersPassword(model.Email, model.Password);

                                    ds.EditUserPassword(user.Id, model.Email, model.Password);

                                    return(new StatusCodeResult(200));
                                }
                                catch
                                {
                                    return(StatusCode(500, "Error occured, please try again"));
                                }
                            }
                        }
                        else
                        {
                            return(BadRequest("The link you clicked on is invalid or has expired. Please contact the administrator."));
                        }
                    }
                    else
                    {
                        return(NotFound("User not found"));
                    }
                }
                else
                {
                    return(BadRequest("Password field is empty"));
                }
            }
            else
            {
                return(BadRequest("Model is wrong"));
            }
        }