コード例 #1
0
ファイル: AccountController.cs プロジェクト: MarlinaJuju/TA
        public ActionResult Login(LoginViewModel l)
        {
            string pw = l.GetPassword(l.Email);

            l.Password = UserViewModel.Encrypt(l.Password);
            if (string.IsNullOrEmpty(pw))
            {
                l.Password = UserViewModel.Decrypt(l.Password);
                ModelState.AddModelError("", "The user login or password provided is incorrect.");
            }
            else
            {
                if (l.Password.Equals(pw))
                {
                    l.Authenticate();
                    Session["permission"] = l.Permissions;
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    //l.Email = UserViewModel.Decrypt(pw);
                    l.Password = UserViewModel.Decrypt(l.Password);
                    ModelState.AddModelError("", "The password provided is incorrect.");
                }
            }
            return(View(l));
        }
コード例 #2
0
        public async Task VerifyIfInitialCallFailsThatItRetries()
        {
            bool firstCall   = true;
            var  authService = new Mock <IAuthenticationService>();

            authService.Setup(service => service.Authenticate(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(
                async(string email, string password) =>
            {
                if (firstCall)
                {
                    firstCall = false;
                    throw await HttpResponseException.CreateException(new HttpResponseMessage());
                }
            });

            var viewModel = new LoginViewModel(authService.Object)
            {
                Email    = "test",
                Password = "******"
            };

            authService.Verify(s => s.Authenticate("test", "test"), Times.Never);
            await viewModel.Authenticate();

            authService.Verify(s => s.Authenticate("test", "test"), Times.Exactly(2)); // Twice cause the first time it throws, but it's still technically called.
        }
コード例 #3
0
        public ActionResult Authenticate(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                bool result;
                try {
                    result = model.Authenticate(model.UserId, model.Password, model.OrgDomainName);
                    if (!result)
                    {
                        TempData["ErrorMessage"] = "認證錯誤";
                        return(RedirectToAction("Index", "Home"));
                    }
                } catch (Exception ex) {
                    //UserSession.ErrorLogging(this.Request.RequestContext, ex);
                    TempData["ErrorMessage"] = "認證錯誤: " + ex.Message;
                    return(RedirectToAction("Index", "Home"));
                }

                UserSession.UserId    = model.UserId;
                UserSession.OrgDomain = model.OrgDomainName;

                //UserSession.UserLogging(model);
                return(RedirectToAction("Index", "Home"));
            }
            return(View());
        }
コード例 #4
0
ファイル: UITests.cs プロジェクト: reddvid/Payroll.Demo
        public void Login()
        {
            var    loginViewModel      = new LoginViewModel();
            string username            = "******";
            string password            = "******";
            bool   isAuthenticatedUser = loginViewModel.Authenticate(username, password);

            Assert.IsTrue(isAuthenticatedUser);
        }
コード例 #5
0
        public async Task VerifyIfCallFailsSeveralTimesItThrowsTheException()
        {
            var authenticationService = new Mock <IAuthenticationService>();

            authenticationService.Setup(service => service.Authenticate(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(
                async(string email, string password) =>
            {
                throw await HttpResponseException.CreateException(new HttpResponseMessage());
            });

            var viewModel = new LoginViewModel(authenticationService.Object)
            {
                Email    = "test",
                Password = "******"
            };

            await Should.ThrowAsync <HttpResponseException>(async() => await viewModel.Authenticate());
        }
コード例 #6
0
        public async Task VerifyLoginCallsAuthenticationOnAuthService()
        {
            var authService = new Mock <IAuthenticationService>();

            authService.Setup(service => service.Authenticate(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(
                async(string email, string password) => new PersonDto {
                Id = 5, Email = email
            });

            var viewModel = new LoginViewModel(authService.Object)
            {
                Email    = "test",
                Password = "******"
            };

            authService.Verify(s => s.Authenticate("test", "test"), Times.Never);
            await viewModel.Authenticate();

            authService.Verify(s => s.Authenticate("test", "test"), Times.Once);
        }
コード例 #7
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            LoginViewModel login = new LoginViewModel();

            login.ViewModelEvent += login_ViewModelEvent;

            string ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

            if (string.IsNullOrEmpty(ip))
            {
                ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }
            else
            {
                ip = ip.Split(',')[0];
            }

            UsersObject user = login.Authenticate(txtUsername.Text, txtPassword.Text, ip, Request.IsLocal);

            if (user != null)
            {
                // User is authenticated
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, txtUsername.Text, DateTime.Now, DateTime.Now.AddHours(8), true, "");

                string cookieEncrypt = FormsAuthentication.Encrypt(ticket);

                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieEncrypt);
                cookie.Path = FormsAuthentication.FormsCookiePath;
                Response.Cookies.Add(cookie);

                if (user.IsSuperAdmin)
                {
                    WebSessionHandler.IsSuperAdmin = true;
                }

                if (user.IsResellerAdmin)
                {
                    WebSessionHandler.IsResellerAdmin      = true;
                    WebSessionHandler.SelectedResellerCode = user.ResellerCode;
                }

                if (user.IsCompanyAdmin)
                {
                    WebSessionHandler.IsCompanyAdmin       = true;
                    WebSessionHandler.SelectedResellerCode = user.ResellerCode;
                    WebSessionHandler.SelectedCompanyCode  = user.CompanyCode;
                }

                if (!string.IsNullOrEmpty(user.DisplayName))
                {
                    WebSessionHandler.DisplayName = user.DisplayName;
                }
                else
                {
                    WebSessionHandler.DisplayName = txtUsername.Text;
                }

                // Redirect to dashbaord
                Server.Transfer("~/dashboard.aspx");
            }
        }
コード例 #8
0
 public void Authenticate()
 {
     _viewModel.Authenticate();
 }
コード例 #9
0
 void Handle_Clicked(object sender, System.EventArgs e)
 {
     viewModel.Authenticate();
 }
コード例 #10
0
 protected override void OnAppearing()
 {
     base.OnAppearing();
     _viewModel.Authenticate();
 }