public bool ForgotPassword(string username, string returnUrl)
        {
            #region Variables
            EmailHelper helper;
            bool        IsComplete  = false;
            bool        status      = false;
            string      UserName    = null;
            string      callbackUrl = null;
            string      htmlmessage = null;
            string      Token       = Guid.NewGuid().ToString();
            string      redirectUri = null;
            bool        ValidEmail  = false;
            DateTime    ExpiryDate;
            string      loginUrl = null;
            #endregion

            try
            {
                #region Initialization
                redirectUri = GenericHelper.EncodeUrl(GetReturnUri(returnUrl));
                ValidEmail  = _identityRepository.ValidateEmail(username.Trim());
                ExpiryDate  = DateTime.Now.AddDays(1);
                loginUrl    = baseIdentityServerUrl + "/ui/login";
                #endregion

                if (ValidEmail)
                {
                    UserName = _identityRepository.GetUserNameByEmail(username.Trim());
                    if (_identityRepository.SaveToken(username.Trim(), Token, ExpiryDate, IsComplete))
                    {
                        callbackUrl = baseIdentityServerUrl + "/ui/ResetPassword?TokenKey=" + Token + "&redirectUri=" + redirectUri;

                        htmlmessage = String.Format("<b>Hi {0}.</b><br/><br/>Please click<b> <a href='{1}'> here </a></b>" +
                                                    "to reset your password. <br/><br/>The link is valid for 24 hours.<br/><br/><br/><b>If you did NOT request a new password," +
                                                    "do not click on the link. </b><br/><br/>You can access the Remote Caretaking system <a href='{2}'> here. </a>",
                                                    UserName, callbackUrl, loginUrl);

                        helper = new EmailHelper(username.Trim(), EmailConstants.From, "Reset password request", "", htmlmessage, null);
                        status = helper.SendEmailAsync().Result;
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Error: Forgot password action not completed --> " + ex.Message);
                throw ex;
            }

            return(status);
        }
Exemple #2
0
        public bool SaveUser(string userEmail, string name, string userPhone, string roleId, bool isEnable, int BoundaryId)
        {
            #region variables
            bool        isEmailSent = false;
            EmailHelper helper;
            bool        IsComplete  = false;
            string      htmlmessage = null;
            string      callbackUrl = null;
            string      loginUrl    = baseUrlIdentityServer + "/ui/login";
            string      Token       = Guid.NewGuid().ToString();
            DateTime    ExpiryDate  = DateTime.Now.AddDays(1);
            string      UserName    = null;
            #endregion

            bool   isUserCreated = _identityRepository.CreateUser(userEmail, name, userPhone, roleId, BoundaryId, isEnable);
            string redirectUri   = GenericHelper.EncodeUrl(GetRedirectUrl(roleId));
            if (isUserCreated)
            {
                #region Send Email to User to activate account
                UserName    = _identityRepository.GetUserNameByEmail(userEmail.Trim());
                callbackUrl = string.Format("{0}/ui/ResetPassword?TokenKey={1}&redirectUri={2}", baseUrlIdentityServer, Token, redirectUri);

                if (_identityRepository.SaveToken(userEmail.Trim(), Token, ExpiryDate, IsComplete))
                {
                    htmlmessage = String.Format("<b>Hi {0}.</b><br/><br/>You have been invited to the BitzerIoc system." +
                                                "<br/><br/>User name = {0} <br/><br/>" +
                                                "To activate your account and create a password please <a href='{1}' > click here. </a>" +
                                                "<br/><br/>Best regards.",
                                                UserName, callbackUrl, loginUrl);


                    helper = new EmailHelper(userEmail.Trim(), EmailConstants.From, "Setup password request", "", htmlmessage, null);

                    isEmailSent = helper.SendEmailAsync().Result;
                }
                #endregion
            }
            return(isEmailSent);
        }