コード例 #1
0
        public IActionResult ResendConfirmCode([FromBody] ResendConfirmCodeRequest request)
        {
            var user = UserService.Get(request.UserID);

            if (user == null)
            {
                return(NotFound(new ResponseModel
                {
                    Success = false,
                    Message = "Пользователь не найден"
                }));
            }

            var session = UserSessionService.GetUserActiveSession(user);

            if (session == null)
            {
                return(NotFound(new ResponseModel
                {
                    Success = false,
                    Message = "Сессия не найдена"
                }));
            }

            UserSessionService.CloseUserActiveSession(user);
            session = UserSessionService.CreateSession(user);

            SmscHelper.SendSms(user.PhoneNumber, $"Код для входа: {session.AuthCode}");

            return(Ok(new SignInResponse
            {
                UserID = user.ID
            }));
        }
コード例 #2
0
        public IActionResult SignIn([FromBody] SignInRequest request)
        {
            var user = UserService.FindByPhoneNumber(request.PhoneNumber);

            if (user == null)
            {
                return(NotFound(new ResponseModel
                {
                    Success = false,
                    Message = "Номер телефона не зарегистрирован"
                }));
            }

            if (UserSessionService.GetUserActiveSession(user) != null)
            {
                UserSessionService.CloseUserActiveSession(user);
            }

            var session = UserSessionService.CreateSession(user);

            SmscHelper.SendSms(user.PhoneNumber, $"Код для входа: {session.AuthCode}");

            return(Ok(new SignInResponse
            {
                UserID = user.ID
            }));
        }
コード例 #3
0
        public IActionResult SignUp([FromBody] SignUpRequest request)
        {
            var user = UserService.FindByPhoneNumber(request.PhoneNumber);

            if (user != null)
            {
                return(BadRequest(new ResponseModel
                {
                    Success = false,
                    Message = "Номер телефона уже используется"
                }));
            }

            user = UserService.FindByEmail(request.Email);
            if (user != null)
            {
                return(BadRequest(new ResponseModel
                {
                    Success = false,
                    Message = "Email уже используется"
                }));
            }

            user = new User
            {
                FirstName    = request.FirstName,
                LastName     = request.LastName,
                PhoneNumber  = request.PhoneNumber,
                Email        = request.Email,
                Role         = UserRole.Client,
                RegisteredAt = DateTime.UtcNow
            };

            UserService.Create(user);

            UserWalletService.Create(new UserWallet
            {
                User    = user,
                Balance = 0
            });

            ProblemService.Create(new Problem
            {
                User        = user,
                ProblemText = request.Problem
            });

            var session = UserSessionService.CreateSession(user);

            SmscHelper.SendSms(user.PhoneNumber, $"Код для входа: {session.AuthCode}");

            return(Ok(new SignInResponse
            {
                UserID = user.ID
            }));
        }