Beispiel #1
0
        public IActionResult CreateToken([FromBody] LoginViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.ToArray()));
            }
            IActionResult respon = Unauthorized();


            if (userBusiness.Authenticate(viewModel.Name, viewModel.Password))
            {
                var thisUser            = userBusiness.GetUser(viewModel.Name);
                var viewModelFromEntity = mapper.Map <User>(thisUser);
                var defaultRoles        = "EMP"; // SET your user role here!
                var tokenStr            = BuildToken(thisUser.Name, defaultRoles);
                respon = Ok(new { token = tokenStr, message = "another message", role = "Employee" });
                // respon = Ok(tokenStr);
            }
            else if (candidateBusiness.Authenticate(viewModel.Name, viewModel.Password))
            {
                var thisCandidate = candidateBusiness.GetCandidateInfo(viewModel.Name);
                var defaultRoles  = "CANDIDATE"; // SET your user role here!
                var tokenStr      = BuildToken(thisCandidate.UserName, defaultRoles);
                respon = Ok(new { token = tokenStr, message = "another message", role = "Candidate" });
            }
            return(respon);
        }
Beispiel #2
0
 public IActionResult getCandidateByName(string name)
 {
     return(Ok(candidateBusiness.GetCandidateInfo(name)));
 }