コード例 #1
0
        public int SaveOtp(UserValidationOtp userValidationOtp)
        {
            using IDbConnection db = _connectionFactory.GetConnection;
            int userId = db.Query <int>(@"Select u.UserId [UserValidationOtp] Where u.UserId = @UserId", new { userValidationOtp.UserId }).FirstOrDefault();

            string query = userId > 0 ?
                           @"update [UserValidationOtp] Set 
                    otp = @otp,
                    OtpGeneratedTime = @OtpGeneratedTime,
                    OtpAuthenticatedTime = @OtpAuthenticatedTime,
                    Status = @Status,
                    Type = @Type,
                    OrgId = @OrgId,
                    Where UserId = @UserId"
                :
                           @"Insert into [UserValidationOtp](UserId, otp, OtpGeneratedTime, OtpAuthenticatedTime, Status, Type, OrgId) 
                values (@UserId, @otp, @OtpGeneratedTime, @OtpAuthenticatedTime, @Status, @Type, @OrgId)";

            return(db.Execute(query, userValidationOtp));
        }
コード例 #2
0
        public bool SendOtp(string userName)
        {
            try
            {
                PasswordLogin passwordLogin = _authenticationRepository.GetLoginPassword(userName);
                var           user          = _userRepository.Get(passwordLogin.UserId);
                string        otp           = GenericUtil.GenerateOTP().ToString();
                new KromeEmail().SendEmail(user.Email, otp, GenericUtil.OTPTransType.PasswordReset);
                new KromeSMS().SendSMS(user.Mobile, otp, GenericUtil.OTPTransType.PasswordReset);

                UserValidationOtp userValidationOtp = new UserValidationOtp
                {
                    UserId = passwordLogin.UserId,
                    OrgId  = user.OrgId,
                    otp    = otp,
                    OtpAuthenticatedTime = DateTime.Now,
                    OtpGeneratedTime     = DateTime.Now,
                    Status = (int)GenericUtil.OTPTransType.PasswordReset,
                    Type   = GenericUtil.OTPTransType.PasswordReset.ToString()
                };

                _authenticationRepository.SaveOtp(userValidationOtp);

                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogException(new ExceptionLog
                {
                    ExceptionDate   = DateTime.Now,
                    ExceptionMsg    = ex.Message,
                    ExceptionSource = ex.Source,
                    ExceptionType   = "UserService",
                    FullException   = ex.StackTrace
                });
                return(false);
            }
        }