Ejemplo n.º 1
0
        public async Task <ChangePinResultWebModel> ChangePin(ChangePinWebModel model)
        {
            string newPin = model.Pin;

            if (new AccessPinHelper().Validate(newPin) == false)
            {
                throw new Exception("Bad pin");
            }

            var db        = new ApplicationDbContext();
            var logic     = new UserProfileLogic(db);
            var myAthlete = logic.GetAthleteForUserName(User.Identity.Name);

            string oldPin = logic.GetPin(myAthlete.AthleteID);

            logic.SetPin(myAthlete.AthleteID, newPin);

            // try changing the password
            // this will only work if the old pin was the password, otherwise this will fail and the password will stay
            try
            {
                var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), oldPin, newPin);

                if (result.Succeeded)
                {
                    return new ChangePinResultWebModel()
                           {
                               PinChanged = true, PasswordChanged = true
                           }
                }
                ;
            }
            catch (Exception)
            {
            }

            return(new ChangePinResultWebModel()
            {
                PinChanged = true, PasswordChanged = false
            });
        }
Ejemplo n.º 2
0
        public async Task <ChangePinResultWebModel> ChangePin(string pin)
        {
            string url = WebApiUrl + "Account/ChangePin";

            try
            {
                ChangePinWebModel model = new ChangePinWebModel()
                {
                    Pin = pin
                };
                string json = await this.sendPostRequestAndReceiveResponse(url, model, true);

                ChangePinResultWebModel result = JsonConvert.DeserializeObject <ChangePinResultWebModel>(json);
                return(result);
            }
            catch (Exception exc)
            {
                LastExceptionUrl = url;
                lastException    = exc;
                return(null);
            }
        }