コード例 #1
0
ファイル: AccountService.cs プロジェクト: Milvasoft/Milvasoft
        /// <summary>
        /// Sends verification code to logged-in user's phone number.
        /// <para><b> IMPORTANT INFORMATION : The message sending service has not yet been integrated.
        ///                                   So this method will not send message to the user's gsm number.
        ///                                   Instead of returns verification code for testing. </b></para>
        /// </summary>
        /// <returns></returns>
        public async Task <string> SendPhoneNumberVerificationMessageAsync()
        {
            CheckLoginStatus();

            var user = await _userRepository.GetFirstOrDefaultAsync(a => a.UserName == _userName).ConfigureAwait(false);

            if (string.IsNullOrWhiteSpace(user?.PhoneNumber))
            {
                throw new MilvaUserFriendlyException("IdentityInvalidPhoneNumber");
            }

            var verificationCode = GenerateVerificationCode();

            if (!_redisCacheService.IsConnected())
            {
                try
                {
                    await _redisCacheService.ConnectAsync().ConfigureAwait(false);
                }
                catch (Exception)
                {
                    _ = _milvaLogger.LogFatalAsync("Redis is not available!!", MailSubject.ShutDown);
                    throw new MilvaUserFriendlyException("CannotSendMessageNow");
                }
            }

            await _redisCacheService.SetAsync($"pvc_{_userName}", verificationCode, TimeSpan.FromMinutes(3)).ConfigureAwait(false);

            //Doğrulama kodunu mesaj olarak gönderme entegrasyonu buraya eklenecek.
            //O yüzden şimdilik geriye dönüyoruz bu kodu.

            return(verificationCode);
        }
コード例 #2
0
    /// <summary>
    /// It performs the requested redis action in try catch blocks. If redis client not connected, connects.
    /// If an error occurs when performing action or connecting to redis, it throws the <see cref="MilvaUserFriendlyException"/> error along with the message key.
    /// Fatal logging if <paramref name="milvaLogger"/> object is not null.
    /// </summary>
    /// <param name="action"></param>
    /// <param name="userFriendlyMessageLocalizerKey"></param>
    /// <param name="milvaLogger"></param>
    /// <returns></returns>
    public async Task <T> PerformRedisActionAsync <T>(Func <Task <T> > action, string userFriendlyMessageLocalizerKey, IMilvaLogger milvaLogger = null)
    {
        try
        {
            await CheckClientAndConnectIfNotAsync().ConfigureAwait(false);

            if (IsConnected())
            {
                return(await action().ConfigureAwait(false));
            }
            else
            {
                throw new MilvaUserFriendlyException(userFriendlyMessageLocalizerKey);
            }
        }
        catch (MilvaUserFriendlyException)
        {
            if (milvaLogger != null)
            {
                _ = milvaLogger.LogFatalAsync("Cannot reach redis server.", MailSubject.Error);
            }

            throw;
        }
    }