示例#1
0
        public IHttpResponse PostLogin(DoLoginViewModel model)
        {
            model.Password = this.hashService.Compute256Hash(model.Password);

            if (!(this.Context.Users.Any(user =>
                                         (user.Username == model.UsernameOrEmail.Trim() || user.Email == model.UsernameOrEmail.Trim()) &&
                                         user.Password == model.Password)))
            {
                GetLoginViewModel viewModel = new GetLoginViewModel()
                {
                    ErrorMessage = InvalidLoginInformationMessage
                };

                return(this.View("Login", HttpResponseStatusCode.BadRequest, viewModel));
            }
            else
            {
                string username =
                    this.Context
                    .Users
                    .Where(user => user.Username == model.UsernameOrEmail.Trim() || user.Email == model.UsernameOrEmail.Trim())
                    .First()
                    .Username;

                var viewModel = model.To <DoLoginViewModel>();

                HttpCookie cookie = new HttpCookie(AuthenticationCookieKey, this.UserCookieService.EncryptString(username, EncryptKey));

                this.Request.Cookies.Add(cookie);
                this.Response.Cookies.Add(cookie);

                return(this.View("Logged", HttpResponseStatusCode.Ok, viewModel));
            }
        }
示例#2
0
        public IHttpResponse Login(DoLoginViewModel model)
        {
            var hashedPassword = this.hashService.Hash(model.Password);

            var user = this.Db.Users.FirstOrDefault(x =>
                                                    x.Username == model.Username.Trim() &&
                                                    x.Password == hashedPassword);

            if (user == null)
            {
                return(this.BadRequestErrorWithView("Invalid username or password."));
            }

            var mvcUser = new MvcUserInfo {
                Username = user.Username, Role = user.Role.ToString(), Info = user.Email
            };
            var cookieContent = this.UserCookieService.GetUserCookie(mvcUser);

            var cookie = new HttpCookie(".auth-cakes", cookieContent, 7)
            {
                HttpOnly = true
            };

            this.Response.Cookies.Add(cookie);
            return(this.Redirect("/"));
        }
        public async Task <ActionResult> DoLogin(DoLoginViewModel model)
        {
            bool isExist = false;

            using (var chanel = new ChanelFactory())
            {
                isExist = await chanel.CheckCusExist <bool>(model.CustomerCode.Trim());

                if (isExist)
                {
                    var result = await chanel.Login <bool>(model.CustomerCode.Trim(), model.Password);

                    if (result)
                    {
                        FormsAuthentication.SetAuthCookie(model.CustomerCode, false);
                        return(Json(new { IsSuccess = true }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { IsSuccess = false, Error = Einvoice_Customer.Language.Resource.ErrorPass }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json(new { IsSuccess = false, Error = Einvoice_Customer.Language.Resource.usernotExist }, JsonRequestBehavior.AllowGet));
                }
            }
        }
 public IActionResult DoLogin(string spusername, string sppassword)
 {
     if (_authenticationService.TryLoginCredentials(spusername, sppassword))
     {
         var        viewModel = new DoLoginViewModel();
         WebSession session   = _authenticationService.CreateWebSession(spusername);
         viewModel.Message = "Created new web session valid until " + session.Expiry.ToShortDateString();
         _cookie.Set("ReportSession", session.SessionCookie, new CookieOptions()
         {
             HttpOnly = true, Expires = DateTime.UtcNow.AddDays(13)
         });
         return(View(viewModel));
     }
     return(RedirectToAction("Login", "Account"));
 }
示例#5
0
        public IHttpResponse Index()
        {
            if (this.Request.Cookies.ContainsCookie(AuthenticationCookieKey) &&
                this.Request.Cookies.GetCookie(AuthenticationCookieKey).Expires >= DateTime.UtcNow)
            {
                string cookieValue = this.Request.Cookies.GetCookie(AuthenticationCookieKey).Value;

                string username =
                    this.UserCookieService
                    .DecryptString(cookieValue, EncryptKey);

                DoLoginViewModel user = new DoLoginViewModel()
                {
                    UsernameOrEmail = username
                };

                return(this.View("Logged", HttpResponseStatusCode.Ok, user));
            }
            else
            {
                return(this.View <string>("index", HttpResponseStatusCode.Ok));
            }
        }
        public async Task <IActionResult> Login(DoLoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                LearningPlusUser user = await userManager.FindByNameAsync(model.Username);

                if (user != null)
                {
                    await signInManager.SignOutAsync();

                    Microsoft.AspNetCore.Identity.SignInResult result = await signInManager
                                                                        .PasswordSignInAsync(user, model.Password, model.RememberMe, false);

                    if (result.Succeeded)
                    {
                        return(Redirect(returnUrl ?? "/"));
                    }
                }

                ModelState.AddModelError(nameof(DoLoginViewModel.Username), "Invalid user or password");
            }
            return(View(model));
        }