public async Task <IActionResult> Signin([Bind("MobileNumber,Password")] UserSigninViewModel user)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(Redirect("/"));
            }

            if (ModelState.IsValid)
            {
                RequestUserSigninDto request = new RequestUserSigninDto()
                {
                    MobileNumber = user.MobileNumber,
                    Password     = user.Password
                };
                var result = await _usersFacad.UserSigninService.Execute(request);



                switch (result.Status)
                {
                case ServiceStatus.Success:
                    await HttpContext.LoginToSiteAsync(result.Data.Id, user.MobileNumber, result.Data.Name, result.Data.UserInRole);

                    ViewBag.Message = "باموفقیت وارد شدید";
                    break;

                case ServiceStatus.SystemError:
                    ViewBag.Message = "مشکلی در سیستم پیش آمد";
                    break;

                case ServiceStatus.NotFound:
                    ViewBag.Message = "کاربری با این مشخصات یافت نشد";
                    break;

                case ServiceStatus.Error:
                    ViewBag.Message = result.Message;
                    break;
                }

                return(View("ShowMessage"));
            }
            return(View(user));
        }
Exemplo n.º 2
0
        public async Task <ResultDto <ResultUserSignin> > Execute(RequestUserSigninDto request)
        {
            return(await Task.Run(async() =>
            {
                try
                {
                    var user = await _context.Users
                               .FirstOrDefaultAsync(u => u.MobileNumber == request.MobileNumber && u.Password == request.Password.ToHashed());

                    if (user == null)
                    {
                        return new ResultDto <ResultUserSignin>()
                        {
                            Status = ServiceStatus.NotFound,
                        };
                    }


                    return new ResultDto <ResultUserSignin>()
                    {
                        Status = ServiceStatus.Success,
                        Data = new ResultUserSignin()
                        {
                            Id = user.Id,
                            Name = user.Name,
                            UserInRole = user.UserInRole,
                        }
                    };
                }
                catch (Exception)
                {
                    return new ResultDto <ResultUserSignin>()
                    {
                        Status = ServiceStatus.SystemError
                    };
                };
            }));
        }