Example #1
0
        public ClientModel GetClient(ClientLoginBindingModel clientModel)
        {
            ClientWithPasswordModel clientWithPassword = this.clientRepository.GetClientByUsername(clientModel.Username);

            if (clientWithPassword == null)
            {
                return(null);
            }

            string actualPasswordHash = PasswordUtilities.GeneratePasswordHash(clientModel.Password, clientWithPassword.PasswordSalt);

            if (actualPasswordHash != clientWithPassword.PasswordHash)
            {
                return(null);
            }

            ClientModel client = new ClientModel(clientWithPassword.Id, clientWithPassword.Username, clientWithPassword.Role);

            return(client);
        }
Example #2
0
        public ActionResult Login(ClientLoginBindingModel clientModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(clientModel));
            }

            ClientModel client = this.clientManager.GetClient(clientModel);

            if (client == null)
            {
                this.TempData.Add(TempDataErrorMessageKey, InvalidCredentials);
                return(this.View(clientModel));
            }

            this.Session[SessionUserKey] = client;
            this.TempData.Add(TempDataSuccessMessageKey, LoginSuccessful);

            return(this.RedirectToAction(nameof(OrdersController.Index), Orders));
        }
        public ActionResult Login(ClientLoginBindingModel model, string returnUrl)
        {
            var pairs = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("grant_type", "password"),
                new KeyValuePair <string, string>("username", model.UserName),
                new KeyValuePair <string, string>("password", model.Password)
            };
            var content = new FormUrlEncodedContent(pairs);

            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:44371/");
                var response = client.PostAsync("Token", content).Result;
                var token    = response.Content.ReadAsStringAsync().Result;
                Response.Cookies.Add(CreateCookie(token));

                return(RedirectToAction("Index", "BookView"));
            }
        }