Пример #1
0
        public ActionResult Index(LoginViewModel loginViewModel)
        {
            if (ModelState.IsValid)
            {
                loginViewModel.login.username = loginViewModel.Username;
                loginViewModel.login.password = loginViewModel.Password;

                try
                {
                    if (loginClient.DoesUserExist(loginViewModel.login))
                    {
                        ModelState.AddModelError("", "Sorry, we can't find you in our system, please try again or register");
                    }
                    else
                    {
                        loginClient.DecryptPassword(loginViewModel.login);
                        SessionLogin.UserName = loginViewModel.Username;
                        return(RedirectToAction("MyProfile"));
                    }
                }
                catch (FaultException)
                {
                    ModelState.AddModelError("", "Sorry, we can't find you in our system, please try again or register");
                }
            }
            return(View(loginViewModel));
        }
Пример #2
0
        private void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            LoginWindow logWin = new LoginWindow();
            Login       login  = new Login();

            login.username = usernameTextbox.Text;
            login.password = passwordBox.Password;

            try
            {
                if (!string.IsNullOrEmpty(login.username) && !string.IsNullOrEmpty(login.password))
                {
                    if (loginClient.DoesUserExist(login))
                    {
                        loginClient.EncryptAdminPassword(login);
                        MessageBox.Show("Successfully Registered");
                    }
                    else
                    {
                        MessageBox.Show("A user with that username already exists");
                    }
                }
                else
                {
                    MessageBox.Show("Fill out all fields", "Fill out all fields");
                }
            }
            catch (Exception)
            {
                throw;
            }
            Close();
            logWin.Show();
        }
Пример #3
0
        public ActionResult Register(RegisterViewModel registerViewModel)
        {
            if (ModelState.IsValid)
            {
                registerViewModel.user.name      = registerViewModel.Name;
                registerViewModel.user.lastName  = registerViewModel.LastName;
                registerViewModel.user.country   = registerViewModel.country;
                registerViewModel.user.phone     = registerViewModel.Phone;
                registerViewModel.login.username = registerViewModel.Username;
                registerViewModel.login.password = registerViewModel.Password;

                if (loginClient.DoesUserExist(registerViewModel.login))
                {
                    loginClient.AddGuestAndLoginEncryptPw(registerViewModel.login, registerViewModel.user);
                    return(RedirectToAction("Login"));
                }
                else
                {
                    ModelState.AddModelError("", "A user with the specified username already exist !");
                }
            }
            return(View(registerViewModel));
        }
Пример #4
0
        private void Login()
        {
            Home  home  = new Home();
            Login login = new Login();

            login.username = usernameTextbox.Text;
            login.password = passwordBox.Password;
            if (!string.IsNullOrEmpty(login.username) && !string.IsNullOrEmpty(login.password))
            {
                try
                {
                    if (loginClient.DoesUserExist(login))
                    {
                        MessageBox.Show("Could not find the login in the system", "Failed attempt", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        var currentLogin = loginClient.DecryptPassword(login);
                        if (currentLogin != null)
                        {
                            MessageBox.Show("Successfully logged in", "Success", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                            home.Show();
                            Close();
                        }
                    }
                }
                catch (FaultException)
                {
                    MessageBox.Show("Could not find the login in the system", "Failed attempt", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("Fill out all fields", "Fill out all fields");
            }
        }