Exemple #1
0
        public async Task <ActionResult> ChangeLogin(ChangeLogin model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            //var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);
            //if (result.Succeeded)
            //{
            var context = new ApplicationDbContext();
            var person  = context.Users.FirstOrDefault(x => x.UserName.ToLower() == model.OldLogin.ToLower());
            var user    = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            if (user != null && person.Id == user.Id && Uniq(model.NewLogin))
            {
                person.UserName = model.NewLogin;
                context.SaveChanges();
                await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                return(RedirectToAction("Index", new { Message = ManageMessageId.LoginChangeSuccess }));
            }
            else
            {
                return(View(model));
            }

            //}
            //AddErrors(result);

            return(View(model));
        }
Exemple #2
0
        public async Task <bool> LoginChangeAsync(ChangeLogin login)
        {
            bool output = false;

            if (login != null && !string.IsNullOrEmpty(login.Username) &&
                !string.IsNullOrEmpty(login.OldPassword) && !string.IsNullOrEmpty(login.NewPassword) && IsConnected)
            {
                try
                {
                    var response        = client.PutAsync($"api/Authenticate", new StringContent(JsonConvert.SerializeObject(login), System.Text.Encoding.UTF8, "application/json")).Result;
                    var output_response = await response.Content.ReadAsStringAsync();

                    if (!string.IsNullOrEmpty(output_response))
                    {
                        if (bool.Parse(output_response))
                        {
                            output = true;
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message, e.InnerException);
                }
            }
            return(output);
        }
Exemple #3
0
        public ChangePwdModel()
        {
            Title = "Cambio Password";

            Login = new ChangeLogin()
            {
                Username = "", OldPassword = "", NewPassword = ""
            };
            MessagingCenter.Subscribe <ChangePwd>(this, "LoginChange", async(obj) =>
            {
                var esito = await DataStore.LoginChangeAsync(Login);

                if (esito)
                {
                    Esito = "Credenziali variate correttamente";
                }
                else
                {
                    Esito = "Errore nella variazione della password";
                }
            });
        }