Exemplo n.º 1
0
        private void SendActivateMail(UserInfo user)
        {
            var dbMessageTemplate = new MessageTemplateDataContext(SystemSetting.SageFrameConnectionString);
            MessageTokenDataContext messageTokenDB = new MessageTokenDataContext(SystemSetting.SageFrameConnectionString);

            var messageTemplates = dbMessageTemplate.sp_MessageTemplateByMessageTemplateTypeID(SystemSetting.ACTIVATION_SUCCESSFUL_EMAIL, GetPortalID);

            foreach (var messageTemplate in messageTemplates)
            {
                var            linqActivationTokenValues = messageTokenDB.sp_GetActivationSuccessfulTokenValue(user.UserName, GetPortalID);
                CommonFunction comm = new CommonFunction();
                DataTable      dtActivationSuccessfulTokenValues = comm.LINQToDataTable(linqActivationTokenValues);
                string         replaceMessageSubject             = MessageToken.ReplaceAllMessageToken(messageTemplate.Subject, dtActivationSuccessfulTokenValues);
                string         replacedMessageTemplate           = MessageToken.ReplaceAllMessageToken(messageTemplate.Body, dtActivationSuccessfulTokenValues);
                try
                {
                    MailHelper.SendMailNoAttachment(messageTemplate.MailFrom, user.Email, replaceMessageSubject, replacedMessageTemplate, string.Empty, string.Empty);
                }
                catch (Exception)
                {
                    ShowMessage("", GetSageMessage("UserRegistration", "SecureConnectionUAEmailError"), "", SageMessageType.Alert);
                    return;
                }
            }
        }
        private void SendActivateMail(UserInfo user)
        {
            var dbMessageTemplate = new MessageTemplateDataContext(SystemSetting.SageFrameConnectionString);
            MessageTokenDataContext messageTokenDB = new MessageTokenDataContext(SystemSetting.SageFrameConnectionString);
             
            var messageTemplates = dbMessageTemplate.sp_MessageTemplateByMessageTemplateTypeID(SystemSetting.ACTIVATION_SUCCESSFUL_EMAIL, GetPortalID);
            foreach (var messageTemplate in messageTemplates)
            {
                var linqActivationTokenValues = messageTokenDB.sp_GetActivationSuccessfulTokenValue(user.UserName, GetPortalID);
                CommonFunction comm = new CommonFunction();
                DataTable dtActivationSuccessfulTokenValues = comm.LINQToDataTable(linqActivationTokenValues);
                string replaceMessageSubject = MessageToken.ReplaceAllMessageToken(messageTemplate.Subject, dtActivationSuccessfulTokenValues);
                string replacedMessageTemplate = MessageToken.ReplaceAllMessageToken(messageTemplate.Body, dtActivationSuccessfulTokenValues);
                try
                {
                    MailHelper.SendMailNoAttachment(messageTemplate.MailFrom, user.Email, replaceMessageSubject, replacedMessageTemplate, string.Empty, string.Empty);
                }
                catch (Exception)
                {

                    ShowMessage("", GetSageMessage("UserRegistration", "SecureConnectionUAEmailError"), "", SageMessageType.Alert);
                    return;
                }
            }                      
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SageFrameConfig pagebase = new SageFrameConfig();

            IsUseFriendlyUrls = pagebase.GetSettingBollByKey(SageFrameSettingKeys.UseFriendlyUrls);
            hypGotoLogin.Text = GetSageMessage("UserRegistration", "GoToLogin");
            if (IsUseFriendlyUrls)
            {
                if (GetPortalID > 1)
                {
                    hypGotoLogin.NavigateUrl = ResolveUrl("~/portal/" + GetPortalSEOName + "/" + pagebase.GetSettingsByKey(SageFrameSettingKeys.PortalLoginpage) + ".aspx");
                }
                else
                {
                    hypGotoLogin.NavigateUrl = ResolveUrl("~/" + pagebase.GetSettingsByKey(SageFrameSettingKeys.PortalLoginpage) + ".aspx");
                }
            }
            else
            {
                hypGotoLogin.NavigateUrl = ResolveUrl("~/Default.aspx?ptlid=" + GetPortalID + "&ptSEO=" + GetPortalSEOName + "&pgnm=" + pagebase.GetSettingsByKey(SageFrameSettingKeys.PortalLoginpage));
            }
            if (!IsPostBack)
            {
                try
                {
                    MessageTemplateDataContext dbMessageTemplate = new MessageTemplateDataContext(SystemSetting.SageFrameConnectionString);

                    string ActivationCode = string.Empty;
                    if (Request.QueryString["ActivationCode"] != null)
                    {
                        ActivationCode = Request.QueryString["ActivationCode"].ToString();
                        try
                        {
                            ActivationCode = EncryptionMD5.Decrypt(ActivationCode);
                        }
                        catch
                        {
                            ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("UserRegistration", "InvalidActivationCode"), "", SageMessageType.Alert);
                            return;
                        }

                        UserManagementDataContext dbUser = new UserManagementDataContext(SystemSetting.SageFrameConnectionString);
                        var sageframeuser = dbUser.sp_GetUsernameByActivationOrRecoveryCode(ActivationCode, GetPortalID).SingleOrDefault();
                        if (sageframeuser.CodeForUsername != null)
                        {
                            if (!(bool)(sageframeuser.IsAlreadyUsed))
                            {
                                string UserName = _member.ActivateUser(ActivationCode, GetPortalID, GetStoreID);
                                if (!String.IsNullOrEmpty(UserName))
                                {
                                    UserInfo user = _member.GetUserDetails(GetPortalID, UserName);
                                    if (user.UserExists)
                                    {
                                        var messageTemplates = dbMessageTemplate.sp_MessageTemplateByMessageTemplateTypeID(SystemSetting.ACTIVATION_SUCCESSFUL_EMAIL, GetPortalID);
                                        foreach (var messageTemplate in messageTemplates)
                                        {
                                            var            linqActivationTokenValues = messageTokenDB.sp_GetActivationSuccessfulTokenValue(user.UserName, GetPortalID);
                                            CommonFunction comm = new CommonFunction();
                                            DataTable      dtActivationSuccessfulTokenValues = comm.LINQToDataTable(linqActivationTokenValues);
                                            string         replaceMessageSubject             = MessageToken.ReplaceAllMessageToken(messageTemplate.Subject, dtActivationSuccessfulTokenValues);
                                            string         replacedMessageTemplate           = MessageToken.ReplaceAllMessageToken(messageTemplate.Body, dtActivationSuccessfulTokenValues);
                                            try
                                            {
                                                MailHelper.SendMailNoAttachment(messageTemplate.MailFrom, user.Email, replaceMessageSubject, replacedMessageTemplate, string.Empty, string.Empty);
                                            }
                                            catch (Exception)
                                            {
                                                ShowMessage("", GetSageMessage("UserRegistration", "SecureConnectionUAEmailError"), "", SageMessageType.Alert);
                                                return;
                                            }
                                        }
                                        ACTIVATION_INFORMATION.Text = GetSageMessage("UserRegistration", "ActivationSuccessfulInfo");
                                        //ShowMessage("", GetSageMessage("UserRegistration", "ActivationSuccessfulInfo"), "", SageMessageType.Alert);
                                    }
                                    else
                                    {
                                        ShowMessage("", GetSageMessage("UserManagement", "UserDoesNotExist"), "", SageMessageType.Alert);
                                    }
                                }
                                else
                                {
                                    var template = dbMessageTemplate.sp_MessageTemplateByMessageTemplateTypeID(SystemSetting.ACTIVATION_FAIL_INFORMATION, GetPortalID).SingleOrDefault();
                                    if (template != null)
                                    {
                                        ACTIVATION_INFORMATION.Text = template.Body;
                                    }
                                    ;
                                }
                            }
                            else
                            {
                                ShowMessage("", GetSageMessage("UserRegistration", "ActivationCodeAlreadyUsed"), "", SageMessageType.Alert);
                            }
                        }
                        else
                        {
                            ShowMessage("", GetSageMessage("UserManagement", "UserDoesNotExist"), "", SageMessageType.Alert);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ProcessException(ex);
                }
            }
        }