Exemplo n.º 1
0
        public async Task <CodeModel> CreatePhoneCode(string phone, CodeReason codeReason)
        {
            var props = _codeConfiguration.Data[Enum.GetName(typeof(CodeReason), codeReason)];

            return(await _codeRepository.Create(new CodeModel
            {
                Phone = phone,
                Code = GenerateCode(props.CodeLength),
                ReasonType = codeReason,
                DateExpiration = DateTime.UtcNow.AddMinutes(props.LifeTime)
            }));
        }
        public async Task <UserPasswordForgotResponseDto> PasswordForgot(UserPasswordForgotRequestDto requestDto)
        {
            var user = await _userRepository.GetByEmail(requestDto.Email);

            if (user == null)
            {
                return(new UserPasswordForgotResponseDto
                {
                    Error = ErrorCodes.UserEmailNotExists,
                    ErrorField = new List <string> {
                        nameof(requestDto.Email)
                    }
                });
            }

            var res = await _codeRepository.Create(
                new CodeModel
            {
                UserId         = user.Id,
                Code           = _codeService.GenerateCode(6),
                ReasonId       = CodeReason.PasswordForgot,
                DateExpiration = new DateTime().Add(new TimeSpan(0, 0, 30))
            },
                user.Id.Value
                );

            //TODO email send
            return(new UserPasswordForgotResponseDto());
        }
Exemplo n.º 3
0
        public Code Create(long userId, Code toAdd)
        {
            using (var tran = new TransactionScope())
            {
                var toRet = _repository.Create(toAdd);

                //Force cash refresh for all module entries
                CacheHelper.Clear(Module);

                BlLog.Log(userId, Module, "Create code", "CodeCreated", new object[] { toAdd.CodeName, toAdd.TableName });
                tran.Complete();
                return(toRet);
            }
        }