예제 #1
0
        public UserDetailInfoViewModel GetCurrentUserDetail()
        {
            CurrentLoginData currentLogin = CurrentLoginData.FromIdentity(User.Identity as ClaimsIdentity);

            return(new UserDetailInfoViewModel
            {
                RoleNames = currentLogin != null ? currentLogin.RoleNames : null,
                Email = currentLogin != null ? currentLogin.Email : null,
                Id = currentLogin != null ? currentLogin.Id : null,
                UserName = currentLogin != null ? currentLogin.UserName : null
            });
        }
예제 #2
0
        public async Task <IHttpActionResult> SetPassword(SetPasswordBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CurrentLoginData currentLogin = CurrentLoginData.FromIdentity(User.Identity as ClaimsIdentity);

            if (currentLogin == null)
            {
                return(NotFound());
            }

            if (model.NewPassword != model.ConfirmPassword)
            {
                ModelState.AddModelError("", "New and confirm password should be same.");
                return(BadRequest(ModelState));
            }
            else
            {
                MyUser ouser = new MyUser();
                ouser.Id           = currentLogin.Id;
                ouser.Email        = currentLogin.Email;
                ouser.PasswordHash = MyEncryption.Encrypt(model.NewPassword);

                bool flag = false;
                try
                {
                    flag = new MyUserManager().ChangeUserPassword(ouser); //await UserManager.CreateAsync(user, model.Password);
                }
                catch (Exception ex) { ModelState.AddModelError("", ex.Message); }
                if (!flag)
                {
                    ModelState.AddModelError("", "Failed to set user password");
                    return(BadRequest(ModelState));
                }
            }
            return(Ok());
        }