Exemplo n.º 1
0
        private bool ValidateOnLogin()
        {
            try
            {
                var message = string.Empty;

                if (string.IsNullOrWhiteSpace(LoginText))
                {
                    message = Translations.GetTranslation()["EmptyLogin"].ToString();
                }
                else if (Password.Length < 8 || string.IsNullOrWhiteSpace(Password) || Password == string.Empty || !Regex.IsMatch(Password, @"^[a-zA-Z0-9]{8,}$"))
                {
                    message = Translations.GetTranslation()["PassValidation"].ToString();
                }
                else if (UserServiceClient.GetUser(LoginText, AESEncryptor.encryptPassword(Password)) == null)
                {
                    message = Translations.GetTranslation()["LogPassValid"].ToString();
                }

                if (message != string.Empty)
                {
                    Application.Current.Dispatcher.Invoke(new Action((() => { CustomMessageBox.Show(Translations.GetTranslation()["Error"].ToString(), message); })));
                    return(false);
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 private async void ExecuteOnLogin()
 {
     try
     {
         IsLoginProgress = true;
         await Task.Factory.StartNew(() =>
         {
             try
             {
                 if (ValidateOnLogin())
                 {
                     var user = UserServiceClient.GetUser(LoginText, AESEncryptor.encryptPassword(Password));
                     if (user != null)
                     {
                         if (user.Status == "online")
                         {
                             Application.Current.Dispatcher.Invoke(() =>
                             {
                                 CustomMessageBox.Show(
                                     Translations.GetTranslation()["Error"].ToString(),
                                     Translations.GetTranslation()["UserAlreadyOnline"].ToString(),
                                     MessageBoxType.Error);
                             });
                             return;
                         }
                         _serializeUser.SerializeUser(user);
                         Application.Current.Dispatcher.Invoke(() =>
                         {
                             var wnd = new MessageMainWnd(user);
                             wnd.Show();
                             view.CloseWindow();
                             IsLoginProgress = false;
                         });
                     }
                 }
             }
             catch (Exception)
             {
             }
         }).ContinueWith(task => { IsLoginProgress = false; });
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 3
0
        private void OnApply()
        {
            _oldPass = _restorePasswordSupplier.GetCurrentPassword();
            _newPass = _restorePasswordSupplier.GetNewPassword();

            if (Validate())
            {
                IsResetingNotProgress = false;
                IsResetingProgress    = true;

                var result = string.Empty;

                Task.Run(() =>
                {
                    try
                    {
                        GlobalBase.CurrentUser.Password = AESEncryptor.encryptPassword(_newPass);

                        UserServiceClient.AddOrUpdateUser(GlobalBase.CurrentUser);
                    }
                    catch (Exception ex)
                    {
                        result = ex.Message;
                    }
                }).ContinueWith(task =>
                {
                    if (result == string.Empty)
                    {
                        Application.Current.Dispatcher.Invoke(new Action((() =>
                        {
                            CustomMessageBox.Show(Translations.GetTranslation()["ChangesSaved"].ToString());
                            OnBack();
                            return;
                        })));
                    }
                    else
                    {
                        Application.Current.Dispatcher.Invoke(new Action((() =>
                        {
                            CustomMessageBox.Show(Translations.GetTranslation()["Error"].ToString(), result);
                        })));
                    }
                });
            }
        }
Exemplo n.º 4
0
        private void SendPassWithMail(User user)
        {
            try
            {
                var from = new MailAddress("*****@*****.**"); // make custom mail adress
                var to   = new MailAddress(user.Email);

                var newPas = AESEncryptor.encryptPassword(RandomNumberGenerator.RandomPassword());
                user.Password = newPas;

                UserServiceClient.AddOrUpdateUser(user);

                var message = new MailMessage(from, to);
                message.Subject = "Password restore";
                message.Body    = "Your pass - " + AESEncryptor.decryptPassword(newPas);

                var smtp = new SmtpClient("smtp.gmail.com", 587);
                smtp.Credentials = new NetworkCredential("*****@*****.**", "messageApp1");
                smtp.EnableSsl   = true;
                smtp.SendMailAsync(message);

                Application.Current.Dispatcher.Invoke(new Action((() =>
                {
                    try
                    {
                        CustomMessageBox.Show(Translations.GetTranslation()["RestorePass"].ToString(), Application.Current.Resources.MergedDictionaries[4]["EmailSend"].ToString());
                        IsSending = false;
                    }
                    finally
                    {
                    }
                })));
            }
            finally
            {
            }
        }
Exemplo n.º 5
0
        protected override void Seed(UserContext context)
        {
            List <User> defUsers = new List <User>();

            defUsers.Add(new User()
            {
                FirstName = "John", LastName = "Snow", Login = "******", Email = "*****@*****.**", Password = AESEncryptor.encryptPassword("123123aa"), Status = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss")
            });
            defUsers.Add(new User()
            {
                FirstName = "Bill", LastName = "Gates", Login = "******", Email = "*****@*****.**", Password = AESEncryptor.encryptPassword("123123aa"), Status = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss")
            });
            defUsers.Add(new User()
            {
                FirstName = "Harry", LastName = "Potter", Login = "******", Email = "*****@*****.**", Password = AESEncryptor.encryptPassword("123123aa"), Status = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss")
            });
            defUsers.Add(new User()
            {
                FirstName = "Duke", LastName = "Nukem", Login = "******", Email = "*****@*****.**", Password = AESEncryptor.encryptPassword("123123aa"), Status = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss")
            });
            defUsers.Add(new User()
            {
                FirstName = "Will", LastName = "Bedone", Login = "******", Email = "*****@*****.**", Password = AESEncryptor.encryptPassword("123123aa"), Status = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss")
            });

            context.Users.AddRange(defUsers);

            base.Seed(context);
        }
Exemplo n.º 6
0
        private void ExecuteOnRegister()
        {
            try
            {
                IsRegisterProgress = true;
                Task.Run(() =>
                {
                    try
                    {
                        var message = string.Empty;
                        if (ValidateOnRegister())
                        {
                            var user = new User()
                            {
                                Login     = UserLogin,
                                Password  = AESEncryptor.encryptPassword(RPassword),
                                FirstName = Name,
                                LastName  = Surname,
                                Email     = Email,
                                Status    = DateTime.Now.ToString()
                            };

                            if (UserServiceClient.GetUserByLogin(UserLogin) == null)
                            {
                                if (UserServiceClient.AddOrUpdateUser(user) == string.Empty)
                                {
                                    Application.Current.Dispatcher.Invoke(new Action((() =>
                                    {
                                        CustomMessageBox.Show(Translations.GetTranslation()["RegisterDone"].ToString());
                                        Clear();
                                        ExecuteOnBackCommand();
                                        return;
                                    })));
                                }
                                else
                                {
                                    message = Translations.GetTranslation()["RegError"].ToString();
                                }
                            }
                            else
                            {
                                message = Translations.GetTranslation()["SameUserExits"].ToString();
                            }

                            if (message != string.Empty)
                            {
                                Application.Current.Dispatcher.Invoke(new Action(() =>
                                {
                                    CustomMessageBox.Show(Translations.GetTranslation()["Error"].ToString(), message);
                                }));
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }).ContinueWith(task => { IsRegisterProgress = false; });
            }
            catch (Exception)
            {
            }
        }