Example #1
0
        public async Task RecoveryPasswordRequestAsync(string contact, ContactTypeEnum contacType, FrontClientType frontClient)
        {
            // recovery password by Email
            if (contacType == ContactTypeEnum.Email)
            {
                var user = await _userRepository.FirstOrDefaultAsync(p => p.Email == contact);

                if (user == null)
                {
                    throw new ArgumentException($"User is not found");
                }

                await RecoveryPasswordRequestByEmailAsync(contact, user.UserProfile.LanguageId, frontClient);
            }
            // recovery password by Phone
            else if (contacType == ContactTypeEnum.Phone)
            {
                var user = await _userRepository.FirstOrDefaultAsync(p => p.Phone == contact);

                if (user == null)
                {
                    throw new ArgumentException($"User is not found");
                }

                await RecoveryPasswordRequestBySmsAsync(contact, user.UserProfile.LanguageId);
            }
            else
            {
                throw new Exception("Unsupported contact_type");
            }
        }
Example #2
0
        public async Task <IdentityMessageModel> GenerateRecoveryEmail(UserLanguageEnum letterLanguage, string email,
                                                                       string verificationToken, FrontClientType frontClient)
        {
            string mainUrl = "";

            if (frontClient == FrontClientType.AdminPanel)
            {
                mainUrl = _baseAdminUrl;
            }
            else if (frontClient == FrontClientType.WebClient)
            {
                mainUrl = _baseClientUrl;
            }
            else
            {
                throw new Exception("Unsupported front_client_type");
            }

            var confirmationLink = $"{mainUrl}/account/recovery_password/{HttpUtility.UrlEncode(verificationToken)}/{HttpUtility.UrlEncode(email)}";
            var subject          = _emailContentBuilderManager.GetSubject(letterLanguage, LetterTypeEnum.RecoveryPassword);
            var letterParams     = new LetterTextParamsModel()
            {
                LetterLanguage = letterLanguage,
                TypeContact    = ContactTypeEnum.Email,
                LetterType     = LetterTypeEnum.RecoveryPassword,
                Params         = new Dictionary <string, string>()
                {
                    { "contact", email },
                    { "confirmationLink", confirmationLink }
                }
            };

            return(await BuildMessageResultModelAsync(letterParams, email, subject));
        }
Example #3
0
        private async Task RecoveryPasswordRequestByEmailAsync(string contact, int langId, FrontClientType frontClient)
        {
            var verificationToken = await _verificationTokenService.AddAsync(contact, ContactTypeEnum.Email, VerificationTokenTypeEnum.Recovery);

            var emailContent = await _emailTypeBuilderManager.GenerateRecoveryEmail(LanguageHelper.Current.GetUserLanguageTypeByEnum(langId),
                                                                                    contact, verificationToken.Token, frontClient);

            Task.Run(() => { _emailSenderManager.SendEmail(emailContent); });
        }