public void SendLoginDetails(LoginDetailsEmailModel model)
        {
            var templateFilePath = Directory.GetCurrentDirectory()
                                   + Path.DirectorySeparatorChar.ToString()
                                   + "Templates"
                                   + Path.DirectorySeparatorChar.ToString()
                                   + "EmailTemplates"
                                   + Path.DirectorySeparatorChar.ToString()
                                   + "LoginDetailsEmail.html";

            var builder = new BodyBuilder();

            using (StreamReader SourceReader = File.OpenText(templateFilePath))
            {
                builder.HtmlBody = SourceReader.ReadToEnd();
            }

            string messageBody = string.Format(builder.HtmlBody, model.ReceiverName, model.EmailId, model.Password);

            EmailMessageModel messageModel = new EmailMessageModel();

            messageModel.EmailBody = messageBody;
            messageModel.Subject   = model.Subject;
            messageModel.To        = model.ReceiverEmail;

            this.emailSender.SendEmail(messageModel);
        }
Exemple #2
0
        public void SendLoginDetails(string emailId)
        {
            var user = this.userRepository.GetUserByEmailId(emailId);

            if (user == null)
            {
                throw new NotFoundException($"User with emailId {emailId} does not exist.");
            }

            var password = this.cryptoService.Decrypt(user.Password);

            var emailModel = new LoginDetailsEmailModel();

            emailModel.ReceiverEmail = emailId;
            emailModel.ReceiverName  = emailId;
            emailModel.Password      = password;
            emailModel.EmailId       = emailId;
            emailModel.Subject       = "Login details";
            this.emailService.SendLoginDetails(emailModel);
        }
Exemple #3
0
        public bool ApproveUser(string emailId)
        {
            var user = this.userRepository.GetUserByEmailId(emailId);

            if (user != null)
            {
                user.IsActive = true;

                this.userRepository.UpdateUser(user);

                var decryptedPassword             = this.cryptoService.Decrypt(user.Password);
                LoginDetailsEmailModel emailModel = new LoginDetailsEmailModel();
                emailModel.ReceiverEmail = emailId;
                emailModel.ReceiverName  = string.IsNullOrEmpty(user.FirstName) || string.IsNullOrEmpty(user.LastName) ? "user" : user.FirstName + " " + user.LastName;
                emailModel.Password      = decryptedPassword;
                emailModel.EmailId       = emailId;
                emailModel.Subject       = "Login details";
                this.emailService.SendLoginDetails(emailModel);
            }

            return(true);
        }