Ejemplo n.º 1
0
        public async Task <IActionResult> Authenticate([FromBody] Employer empParam)
        {
            string test = (from c in _context.Employer
                           where c.empLogin == empParam.empLogin
                           select c.empPassword).FirstOrDefault();

            if (test != null)
            {
                if (SaltPassword.ComparePassword(test, empParam.empPassword))
                {
                    var emp = _employerService.Authenticate(empParam.empLogin, test);

                    if (emp == null)
                    {
                        return(BadRequest(new { message = "Username or password is incorrect" }));
                    }

                    await _context.SaveChangesAsync();

                    emp.empPassword = null;

                    return(Ok(emp));
                }
                else
                {
                    return(BadRequest(new { message = "Username or password is incorrect" }));
                }
            }
            return(BadRequest(new { message = "Username or password is incorrect" }));
        }