public async Task <IActionResult> Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _commonUserSvc.GetUser(model.Email, model.Password);

                if (user != null)
                {
                    await SignInUser(user, false);

                    if (user.Permission == SystemPermissions.Administrator)
                    {
                        return(RedirectToAction("Index", "Admin"));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid Login");
                }
            }

            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> Login([FromBody] LoginViewModel model)
        {
            var response = new APIResponse <TokenResponseModel>();

            if (ModelState.IsValid)
            {
                var user = await _commonUserSvc.GetUser(model.Email, model.Password);

                if (user != null)
                {
                    //Register user device
                    var device = await RegisterUserDevice(model, user);


                    return(Ok(await CreateEncodedJwtToken(user)));
                }
                else
                {
                    response.Success = false;
                    response.Errors.Add(new Error {
                        Code = Common.Enums.ErrorCode.None, Message = "Invalid login"
                    });
                }
            }
            else
            {
                response.Success = false;
                response.Errors.AddRange(ModelState.ToErrors());
            }

            return(Ok(response));
        }