示例#1
0
        public SimpUser Auth(User u)
        {
            try
            {
                string    api  = hostSettings.Address() + $"Auth/Login";
                WebClient wc   = new WebClient();
                var       json = JsonConvert.SerializeObject(new { validationName = u.ValidationName, password = u.Password.Password });
                wc.Headers[HttpRequestHeader.ContentType] = "application/json";
                var       response  = wc.UploadString(api, "PUT", json);
                TokenData tokendata = JsonConvert.DeserializeObject <TokenData>(response);

                api = hostSettings.Address() + $"Auth/GetUser/{u.ValidationName}";
                wc  = new WebClient();
                wc.Headers[HttpRequestHeader.Authorization] = $"Bearer {tokendata.Token}";
                response = wc.DownloadString(api);
                SimpUser simpUser = JsonConvert.DeserializeObject <SimpUser>(response);
                simpUser.Token = tokendata.Token;

                this.messengerService.Send($"Bejelentkeztél {simpUser.UserName} névvel.", "AuthResult");
                return(simpUser);
            }
            catch (Exception ex)
            {
                this.messengerService.Send("BEJELENTKEZÉS SIKERTELEN", "AuthResult");
                return(new SimpUser());
            }
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MainWindow"/> class.
 /// </summary>
 public MainWindow(string token, SimpUser u)
 {
     if (DesignerProperties.GetIsInDesignMode(this))
     {
         this.Resources.Add("username", "CurrentUser");
     }
     else
     {
         this.token = token;
         this.Resources.Add("token", token);
         this.user = u;
         this.Resources.Add("username", user.UserName);
     }
     this.InitializeComponent();
 }
示例#3
0
        public AuthViewModel(IAuthLogic authLogic)
        {
            this.authLogic = authLogic;

            this.Login = new RelayCommand <PasswordBox>(x => {
                User u = new User {
                    ValidationName = userName, Password = x
                };
                SimpUser s = authLogic.Auth(u);
                if (s.Token != null)
                {
                    MainWindow win = new MainWindow(s.Token, s);
                    win.Show();
                    Application.Current.MainWindow.Close();
                }
            }, true);
        }