Пример #1
0
        private async void OpenPage(string value)
        {
            if (string.IsNullOrWhiteSpace(OldPass) || string.IsNullOrWhiteSpace(NewPass) || string.IsNullOrWhiteSpace(ConfirmPass))
            {
                await App.Current.MainPage.DisplayAlert(AppResource.er, AppResource.body, AppResource.ok);
            }
            else if (!passwordRegExp.IsMatch(OldPass))
            {
                await App.Current.MainPage.DisplayAlert(AppResource.er, AppResource.passv, AppResource.ok);
            }
            else if (!passwordRegExp.IsMatch(NewPass))
            {
                await App.Current.MainPage.DisplayAlert(AppResource.er, AppResource.passv, AppResource.ok);
            }
            else if (NewPass != ConfirmPass)
            {
                await App.Current.MainPage.DisplayAlert(AppResource.er, AppResource.passt, AppResource.ok);
            }
            else
            {
                if (Settings.AccessToken == "")
                {
                    await App.Current.MainPage.DisplayAlert(AppResource.er, AppResource.nonuser, AppResource.ok);

                    await Application.Current.MainPage.Navigation.PushModalAsync(new LoginPage());
                }
                else
                {
                    var npass = new NPass
                    {
                        OldPass     = OldPass,
                        NewPass     = NewPass,
                        ConfirmPass = ConfirmPass
                    };
                    DependencyService.Get <IProgressInterface>().Show();
                    var IsChange = await _apiService.ChangePassAsync(npass, Settings.AccessToken);

                    DependencyService.Get <IProgressInterface>().Hide();

                    if (IsChange)
                    {
                        Settings.Password = NewPass;
                        await Application.Current.MainPage.Navigation.PushModalAsync(new MainMenu());
                    }
                    else
                    {
                        await App.Current.MainPage.DisplayAlert(AppResource.er, AppResource.problem, AppResource.ok);

                        await Application.Current.MainPage.Navigation.PushModalAsync(new ChangePassword());
                    }
                }
            }
        }
Пример #2
0
        public async Task <bool> ChangePassAsync(NPass npass, string accessToken)
        {
            var client = new HttpClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

            var         json    = JsonConvert.SerializeObject(npass);
            HttpContent content = new StringContent(json);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var response = await client.PostAsync(Constants.BaseApiAddress + "api/Account/ChangePassword", content);

            if (response.IsSuccessStatusCode)
            {
                return(true);
            }

            return(false);
        }