public async Task <IActionResult> Login(VMLoginModel model) { ResponseMessage result = new ResponseMessage(); try { var response = _loginService.Login(model); if (response.IsSuccess == true) { var employee = (VMLoginResult)(response.Data); var tokenHandler = new JwtSecurityTokenHandler(); var tokenKey = Encoding.ASCII.GetBytes(_jwtTokenKey); var tokenDescription = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, employee.Name), new Claim(ClaimTypes.Sid, employee.Id.ToString()), new Claim(ClaimTypes.Role, employee.Role.ToString()), }), Expires = DateTime.UtcNow.AddDays(1), SigningCredentials = new SigningCredentials( new SymmetricSecurityKey(tokenKey), SecurityAlgorithms.HmacSha256Signature) }; var tokenDetails = tokenHandler.CreateToken(tokenDescription); var jwtToken = tokenHandler.WriteToken(tokenDetails); result = ResponseMapping.GetResponseMessage(jwtToken, 1, ConstantMessage.LoginSuccess); return(new JsonResult(result)); } result = ResponseMapping.GetResponseMessage(null, 2, response.Message); } catch (Exception ex) { result = ResponseMapping.GetResponseMessage(null, 2, ex.Message.ToString()); } return(new JsonResult(result)); }
public async Task <IActionResult> Login(VMLoginModel details, string returnUrl) { if (ModelState.IsValid) { UserIdentity user = await userManager.FindByEmailAsync(details.Email); if (user != null) { //Everything that is commented in this controller is for email confirmation /*if (!userManager.IsEmailConfirmedAsync(user).Result) * { * ModelState.AddModelError("", "Account not confirmed!"); * return View(details); * } * else if (userManager.IsEmailConfirmedAsync(user).Result) * {*/ await signInManager.SignOutAsync(); Microsoft.AspNetCore.Identity.SignInResult result = await signInManager.PasswordSignInAsync( user, details.Password, false, false); if (result.Succeeded) { if (await userManager.IsInRoleAsync(user, "Admin")) { return(RedirectToAction("AdminPage", "Admin")); } else { return(RedirectToAction("UserPage", "User")); } } /*} * else * { * ModelState.AddModelError(nameof(VMLoginModel.Email), "Account Not Verified"); * }*/ } ModelState.AddModelError(nameof(VMLoginModel.Email), "Username or password does not match our records."); } return(View(details)); }
public async Task <IActionResult> BRLogin(VMLoginModel vm) { if (ModelState.IsValid) { UserIdentity user = await userManager.FindByEmailAsync(vm.Email); if (user != null) { //Added email confirmation validation //Everything that is commented in this controller is for email confirmation /*if (!userManager.IsEmailConfirmedAsync(user).Result) * { * ModelState.AddModelError("", "Account not confirmed!"); * return View(vm); * } * else if(userManager.IsEmailConfirmedAsync(user).Result) * {*/ await signInManager.SignOutAsync(); Microsoft.AspNetCore.Identity.SignInResult result = await signInManager.PasswordSignInAsync( user, vm.Password, false, false); if (result.Succeeded) { return(RedirectToAction("LoggedInBidRequest", "BidRequest")); } /*} * else * { * ModelState.AddModelError(nameof(VMLoginModel.Email), "Account Not Verified"); * }*/ } ModelState.AddModelError(nameof(VMLoginModel.Email), "Invalid user or password"); } return(View(vm)); }
public ResponseMessage Login(VMLoginModel model) { ResponseMessage result = new ResponseMessage(); try { //string password = model.Password; // SimpleCryptService.Factory().Encrypt(model.Password); VMLoginResult employee = new VMLoginResult(); using (_connection = new OracleConnection(_dbConnectionString)) { using (_command = new OracleCommand()) { _command.BindByName = true; _command.Connection = _connection; _connection.Open(); //_command.CommandText = $"select * from tblemployeeinformation where email='{model.Email}' and password='******'"; _command.CommandText = "SP_LOGIN"; _command.Parameters.Add("p_email", model.Email); _command.Parameters.Add("p_password", model.Password); _command.Parameters.Add("p_id", OracleDbType.Int32).Direction = ParameterDirection.Output; _command.Parameters.Add("p_name", OracleDbType.Varchar2, 4000).Direction = ParameterDirection.Output; _command.Parameters.Add("p_type_id", OracleDbType.Varchar2, 4000).Direction = ParameterDirection.Output; /* OracleParameter pName = new OracleParameter(); * pName.ParameterName = "@p_name"; * pName.Direction = ParameterDirection.Output; * pName.OracleDbType = OracleDbType.Varchar2; * pName.Size = 4000; * * OracleParameter pType = new OracleParameter(); * pType.ParameterName = "@p_type_id"; * pType.Direction = ParameterDirection.Output; * pType.OracleDbType = OracleDbType.Varchar2; * pType.Size = 4000;*/ _command.CommandType = CommandType.StoredProcedure; int queryResult = _command.ExecuteNonQuery(); employee.Id = Convert.ToInt32(_command.Parameters["p_id"].Value.ToString()); employee.Name = _command.Parameters["p_name"].Value.ToString(); employee.Role = _command.Parameters["p_type_id"].Value.ToString(); /* _reader = _command.ExecuteReader(); * * while (_reader.Read()) * { * employee.NAME = _reader["NAME"].ToString(); * employee.EMAIL = _reader["EMAIL"].ToString(); * employee.ID = Convert.ToInt32(_reader["ID"]); * employee.TYPE_ID = Convert.ToInt32(_reader["TYPE_ID"]); * }*/ _connection.Close(); } } if (employee.Id <= 0) { return(result = ResponseMapping.GetResponseMessage(null, (int)StatusCode.Faild, ConstantMessage.InvalidCreditional)); } return(result = ResponseMapping.GetResponseMessage(employee, (int)StatusCode.Success, ConstantMessage.LoginSuccess)); } catch (Exception ex) { return(result = ResponseMapping.GetResponseMessage(null, (int)StatusCode.Faild, ex.Message.ToString())); } }