Пример #1
0
        /// <summary>
        ///     This method is used to email a token value to the user in order to rest their password
        /// </summary>
        /// <param name="user">User object</param>
        /// <param name="ExpiaryDate">The expiry DateTime of the token</param>
        /// <returns>bool: true (if email is send correctly) else false</returns>
        internal async Task <bool> PasswordResetAsync(oUser user, DateTime ExpiaryDate)
        {
            try
            {
                /// Create the URL for the user to go to in order to reset their password
                string PasswordResetUrl = await GetUrlWithToken(
                    user,
                    TokenType.ResetPassword,
                    ExpiaryDate).ConfigureAwait(false);

                /// The following methods must be called in order to create the email.
                /// The order in which this methods are called will determine
                /// the layout of the email from top to bottom.
                string htmlMessage = HtmlCreator
                                     .HeaderText($"Hello {user.FirstName.FirstCap()} {user.Surname.FirstCap()} \n")
                                     .BodyText("If you have requested to reset your password, " +
                                               "please use the link below. Otherwise Ignore this email. \n")
                                     .Button("Reset Password", PasswordResetUrl)
                                     .BodyTextLight("The link will expire on " + ExpiaryDate)
                                     .FooterFinal("", "oSnack.co.uk")
                                     .GetFinalHtml();

                /// pass the information to be used to send the email.
                await SendEmailAsync(user.Email, "Password Reset", htmlMessage).ConfigureAwait(false);

                /// if all goes well then return true
                return(true);
            }
            catch (Exception err)
            {
                /// if there are any exceptions, Log the exception error
                /// on the database and return false to the caller
                await DbContext.AppLogs.AddAsync(new oAppLog
                {
                    Massage    = err.Message,
                    JsonObject = JsonConvert.SerializeObject(err),
                    User       = user
                });

                await DbContext.SaveChangesAsync().ConfigureAwait(false);

                return(false);
            }
        }
Пример #2
0
        /// <summary>
        ///     This method is used to send token to the user after registration in order to
        ///     validate their email address.
        /// </summary>
        /// <param name="user">The user object</param>
        /// <param name="ExpiaryDate">The expiry date for token</param>
        /// <returns>bool: true (if email is send correctly) else false</returns>
        internal async Task <bool> EmailConfirmationAsync(oUser user, DateTime ExpiaryDate)
        {
            try
            {
                /// Create the URL for the user to go to in order to confirm email address
                var EmailConfirmUrl = await GetUrlWithToken(user, TokenType.ConfirmEmail, ExpiaryDate).ConfigureAwait(false);

                /// The following methods must be called in order to create the email.
                /// The order in which this methods are called will determine
                /// the layout of the email from top to bottom.
                var htmlMessage = HtmlCreator
                                  .HeaderText(string.Format("Hello {0} {1}<br />"
                                                            , user.FirstName.FirstCap()
                                                            , user.Surname.FirstCap()))
                                  .HeaderText("Welcome to oSnack.")
                                  .BodyText("Please use the link below to confirm your email address. <br />")
                                  .Button("Confirm Email", EmailConfirmUrl)
                                  .FooterFinal("", "oSnack.co.uk")
                                  .GetFinalHtml();

                /// pass the information to be used to send the email.
                await SendEmailAsync(user.Email, "Confirm Email", htmlMessage);

                /// if all goes well then return true
                return(true);
            }
            catch (Exception err)
            {
                /// if there are any exceptions, Log the exception error
                /// on the database and return false to the caller
                await DbContext.AppLogs.AddAsync(new oAppLog
                {
                    Massage    = err.Message,
                    JsonObject = JsonConvert.SerializeObject(err),
                    User       = user
                });

                await DbContext.SaveChangesAsync();

                return(false);
            }
        }
Пример #3
0
        /// <summary>
        ///     This method is used to send user's new password to the user after registration in order to
        ///     validate their email address. (Employees only)
        /// </summary>
        /// <param name="user">The user object</param>
        /// <param name="ExpiaryDate">The expiry date for token</param>
        /// <returns>bool: true (if email is send correctly) else false</returns>
        internal async Task <bool> NewEmployeePasswordAsync(oUser user, DateTime ExpiaryDate)
        {
            try
            {
                /// The following methods must be called in order to create the email.
                /// The order in which this methods are called will determine
                /// the layout of the email from top to bottom.
                var htmlMessage = HtmlCreator
                                  .HeaderText(string.Format("Hello {0} {1}<br />"
                                                            , user.FirstName.FirstCap()
                                                            , user.Surname.FirstCap()))
                                  .HeaderText("Welcome to oSnack.")
                                  .BodyText($"Your new password is: {user.Password}<br />")
                                  .FooterFinal("", "oSnack.co.uk")
                                  .GetFinalHtml();

                /// pass the information to be used to send the email.
                await SendEmailAsync(user.Email, "You new OSnack password.", htmlMessage);

                /// if all goes well then return true
                return(true);
            }
            catch (Exception err)
            {
                /// if there are any exceptions, Log the exception error
                /// on the database and return false to the caller
                await DbContext.AppLogs.AddAsync(new oAppLog
                {
                    Massage    = err.Message,
                    JsonObject = JsonConvert.SerializeObject(err),
                    User       = user
                });

                await DbContext.SaveChangesAsync();

                return(false);
            }
        }