private async void Signin_Click(object sender, RoutedEventArgs e) { authPanel.IsEnabled = false; AuthModel auth = FormModel.AuthModel; auth.Error = ""; Settings.RememberMe = auth.RememberMe; bool can = true; if (string.IsNullOrWhiteSpace(auth.Email)) { auth.Error += Res.EmailEmpty + "\n"; can = false; } else if (!Regex.IsMatch(auth.Email, @".+@.+\..+")) { auth.Error += Res.EmailInvalid + "\n"; can = false; } if (string.IsNullOrEmpty(passwordBoxAuth.Password)) { auth.Error += Res.PasswordEmpty + "\n"; can = false; } auth.Error = auth.Error.Trim(); if (can) { try { ReqLoginModel model = new ReqLoginModel() { Email = auth.Email, Password = passwordBoxAuth.Password }; ResLoginModel ds = await Account.Login(model); Settings.UserId = ds.Id; Settings.UserToken = ds.Token; Settings.Save(); SignIn?.Invoke(); } catch (WebException we) { auth.Error = GetError(we); } catch (Exception err) { Logger.Error("Auth_Login", err); } } authPanel.IsEnabled = true; }
private async void Signin_Click(object sender, RoutedEventArgs e) { authPanel.IsEnabled = false; backButton.IsEnabled = false; Settings.RememberMe = (bool)rmAuth.IsChecked; try { ReqLoginModel model = new ReqLoginModel() { Email = emailAuth.Text, Password = passAuth.Password }; ResLoginModel ds = await Account.Login(model); Settings.UserId = ds.Id; Settings.UserToken = ds.Token; Settings.Save(); SignIn?.Invoke(); } catch (WebException we) { var s = we.Response; if (s != null) { using (var reader = new StreamReader(s.GetResponseStream())) { string raw = reader.ReadToEnd(); try { JArray jObject = JArray.Parse(raw); foreach (JToken par in jObject.Children()) { NotifyController.Show(PopupNotify.Error, par.Value <string>("property"), ((JProperty)par.Value <JToken>("constraints").First()).Value.ToString(), 4000); } } catch { NotifyController.Show(PopupNotify.Error, Res.Error, raw, 5000); } } } } catch (Exception err) { Logger.Error("Auth_Login", err); } authPanel.IsEnabled = true; backButton.IsEnabled = true; }
public IHttpActionResult LogIn([FromBody] ReqLoginModel Model) { var Response = new ResLoginModel(); if (ModelState.IsValid) { try { var _Query = (from p in DbModel.Paciente join r in DbModel.Registro on p.IdRegistro equals r.idRegistro where r.Emeci == Model.User && r.clave == Model.Password select new { p.idPaciente, r.FechaExpiracion, r.Nombre, r.Apellido }).FirstOrDefault(); if (_Query == null) { return(NotFound()); } if (_Query.FechaExpiracion.HasValue && _Query.FechaExpiracion.Value > DateTime.Now.Date) { var _Cood = (from dt in DbModel.DatosTarjeta where dt.noTarjeta == Model.User && dt.Coordenada == Model.Coordinate && dt.Dato == Model.Value select dt.noTarjeta).FirstOrDefault(); if (_Cood == null) { return(NotFound()); } Response.Token = $"{_Query.idPaciente}/{Guid.NewGuid().ToString().Replace("-", "")}"; Response.UserName = _Query.Nombre.Trim(); Response.UserLastName = _Query.Apellido.Trim(); Response.ImageProfile = GetImageProfile(_Query.idPaciente); Response.Success = true; } } catch { } } if (Response.Success) { return(Ok(Response)); } else { return(NotFound()); } }