Esempio n. 1
0
        public async Task <IActionResult> Authenticate([FromBody] Clients cliParam)
        {
            string test = (from c in _context.clients
                           where c.cliMail == cliParam.cliMail
                           select c.cliPassword).FirstOrDefault();

            if (test != null)
            {
                if (SaltPassword.ComparePassword(test, cliParam.cliPassword))
                {
                    var cli = _clientService.Authenticate(cliParam.cliMail, test);

                    if (cli == null)
                    {
                        return(BadRequest(new { message = "Login ou mots de passe incorrect" }));
                    }

                    await _context.SaveChangesAsync();

                    cli.cliPassword = null;

                    return(Ok(cli));
                }
                else
                {
                    return(BadRequest(new { message = "Login ou mots de passe incorrect" }));
                }
            }
            return(BadRequest(new { message = "Login ou mots de passe incorrect" }));
        }
Esempio n. 2
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" }));
        }