示例#1
0
        public IActionResult login(UserLoignViewModel model)
        {
            var result = _dbManager.login(model);

            if (result != null)
            {
                var tokenHandler    = new JwtSecurityTokenHandler();
                var key             = Encoding.ASCII.GetBytes(_appSettings.Key);
                var tokenDescriptor = new SecurityTokenDescriptor
                {
                    Subject = new ClaimsIdentity(new Claim[]
                    {
                        new Claim(ClaimTypes.Name, model.email.ToString()),
                        new Claim(ClaimTypes.Role, "Admin"),
                        new Claim(ClaimTypes.Version, "V3.1")
                    }),
                    Expires            = DateTime.UtcNow.AddDays(2),
                    SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
                };
                var token = tokenHandler.CreateToken(tokenDescriptor);
                model.password = null;
                model.token    = tokenHandler.WriteToken(token);

                return(Ok(model));
            }
            return(BadRequest(new { message = "soemting Went worong" }));
        }
示例#2
0
        async public Task <IActionResult> LoginUser(UserLoignViewModel model)
        {
            if (model.Id == 0)
            {
                string              data    = JsonConvert.SerializeObject(model);
                StringContent       content = new StringContent(data, Encoding.UTF8, "application/json");
                HttpResponseMessage res     = client.PostAsync(client.BaseAddress + "/login", content).Result;
                var name = res.Content.ReadAsStringAsync();
                UserLoignViewModel user = JsonConvert.DeserializeObject <UserLoignViewModel>(name.Result);

                if (user != null)
                {
                    HttpContext.Session.SetString("token", user.token);

                    return(RedirectToAction("Index", "Employee"));
                }
                else
                {
                    return(RedirectToAction("login", "User"));
                }
            }
            else
            {
                TempData["message"] = "Plz Enter Email and Password";
                return(View("Login"));
            }
        }
示例#3
0
        public UserLoignViewModel login(UserLoignViewModel obj)
        {
            var ent    = _dataConext.UserRegs.FirstOrDefault(x => x.email == obj.email && x.password == obj.password);
            var config = new MapperConfiguration(cfg => cfg.CreateMap <UserReg, UserLoignViewModel>());
            var mapper = new Mapper(config);
            UserLoignViewModel user = mapper.Map <UserLoignViewModel>(ent);

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

            return(user);
        }
 public UserLoignViewModel login(UserLoignViewModel obj)
 {
     return(_dbRepositpory.login(obj));
 }