/// <summary> /// return /// </summary> /// <param name="email"></param> /// <param name="password"></param> /// <returns></returns> public IUserDTO Login(Interfaces.IUserDTO udto) { if (string.IsNullOrWhiteSpace(udto.Email) || string.IsNullOrWhiteSpace(udto.UserPassword)) { return(null); } User u = _ctx.Users.FirstOrDefault(y => y.Email == udto.Email.ToLower()); if (u == null) { return(null); } if (!VerifyPasswordHash(udto.UserPassword, u.PasswordHash, u.PasswordSalt)) { return(null); } var returnUdto = new DAL.Model.DataTransferObjects.UserDTO { Email = u.Email, IsAdmin = u.IsAdmin, UserName = u.UserName, UserId = u.UserId }; return(returnUdto); }
public ActionResult <Dictionary <string, string> > Login(DAL.Model.DataTransferObjects.UserDTO u) { Dictionary <string, string> cookie = new Dictionary <string, string>(); if (u.Email == null || u.UserPassword == null) { cookie.Add("status", "failedlogin"); return(cookie); } Interfaces.IUserDTO ur = _user.Login(u); if (ur.UserId != 0) { if (ur.IsAdmin == true) { HttpContext.Session.SetString("status", "admin"); } else { HttpContext.Session.SetString("status", "user"); } cookie.Add("userid", ur.UserId.ToString()); cookie.Add("status", HttpContext.Session.GetString("status")); } else { cookie.Add("status", "failedlogin"); } return(cookie); }
public IActionResult Login([FromBody] DAL.Model.DataTransferObjects.UserDTO u) { var user = _user.Login(u); if (user == null) { return(BadRequest("Uname o Upass is incorrect")); } var tokenHandler = new JwtSecurityTokenHandler(); var key = System.Text.Encoding.ASCII.GetBytes(_appSettings.Secret); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.UserId.ToString()) }), Expires = DateTime.UtcNow.AddDays(1), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var tokenstring = tokenHandler.WriteToken(token); HttpContext.Session.SetString("token", tokenstring); HttpContext.Session.SetString("isAdmin", user.IsAdmin.ToString()); HttpContext.Session.SetString("userName", user.UserName); return(Ok(new { Id = user.UserId, Username = user.UserName, Token = tokenstring, IsAdmin = (bool)user.IsAdmin })); //if (u.Email == null || u.UserPassword == null) //{ // return BadRequest("Username or password is incorrect"); //} //Interfaces.IUserDTO ur = _user.Login(u); //if (ur.UserId != 0) //{ // if (ur.IsAdmin == true) // { // HttpContext.Session.SetString("status", "admin"); // return Ok(ur); // } // else // { // HttpContext.Session.SetString("status", "user"); // return Ok(ur); // } //} //else //{ // return BadRequest("Username or password is incorrect"); //} }
public IActionResult Registration([FromBody] DAL.Model.DataTransferObjects.UserDTO udto) { try { _user.Registration(udto); return(Ok()); } catch (ApplicationException ex) { return(BadRequest(ex.Message)); } }
public JsonResult Registration(DAL.Model.DataTransferObjects.UserDTO u) { throw new NotImplementedException(); }
public ActionResult <string> Register(DAL.Model.DataTransferObjects.UserDTO udto) { _user.Registration(udto); return(""); }