Esempio n. 1
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = new ApplicationUser()
            {
                UserName = model.Email, Email = model.Email
            };

            //set the IsDeleted property to false
            user.IsDeleted = false;
            UserModal ouser = new UserModal();

            ouser.Id           = user.Id;
            ouser.Email        = user.Email;
            ouser.UserName     = user.UserName;
            ouser.PasswordHash = MyEncryption.Encrypt(model.Password);
            bool flag = false;

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

            return(Ok());
        }
Esempio n. 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());
        }