public ActionResult Register(string Name, string Email, string Password, string Confirmation, string ReturnUrl, List<ProfileFieldInfo> FieldInfo, string RequestID, string SessionID, int TimeZoneOffset)
        {
            AppParams.RefreshAppParameters();
            string AfterSingUpRedirectUrl = "";

            if (AppSession.Parameters.RegistrationSelfRegistration.Value == "false")
            {
                if (AppSession.IsMemberInAdminRole)
                {

                }
                else
                {

                    if (ReturnUrl == null || ReturnUrl.Trim().Length == 0)
                        ReturnUrl = (ReturnUrl != null && ReturnUrl.Length > 0) ? ReturnUrl : ((AppSession.Parameters.RulesRedirectAfterLogin.Value != null && AppSession.Parameters.RulesRedirectAfterLogin.Value.Length > 0) ? AppSession.Parameters.RulesRedirectAfterLogin.Value : Url.Content("~/"));

                    AuditEvent.AppEventError(AppSession.Parameters.GeneralAdminEmail.Value, "Somebody tries to Register notification but it was switched off. ", AuditEvent.GetSessionDetails());
                    return new RedirectResult(ReturnUrl);
                }
            }

            RequestResultModel _model = new RequestResultModel();

            if (AppSession.IsEmail(Name))
            {
                _model.Message += String.Format("<li>{0}</<li>", GetLabel("Account.CreateAccount.NameLooksLikeEmail"));
            }

            if (Name == null || Name.Trim().Length == 0 ||
               ((Password == null || Password.Trim().Length == 0)) ||
               Email == null || Email.Trim().Length == 0 ||
               Password != Confirmation ||
               !AppSession.IsEmail(Email) ||
               (Password != null && Password.Length > 0 && Password.Length <=3) ||
               (Confirmation != null && Confirmation.Length > 0 && Confirmation.Length <=3))
            {
                if (Name == null || Name.Trim().Length == 0)
                    _model.Message += String.Format("<li>{0}</<li>", GetLabel("Account.CreateAccount.NameIsEmpty"));

                if ((Password == null || Password.Trim().Length == 0))
                    _model.Message += String.Format("<li>{0}</<li>", GetLabel("Account.CreateAccount.PasswordIsEmty"));

                if (Email == null || Email.Trim().Length == 0)
                    _model.Message += String.Format("<li>{0}</<li>", GetLabel("Account.CreateAccount.EmailIsEmpty"));

                if (Email != null && !AppSession.IsEmail(Email))
                    _model.Message += String.Format("<li>{0}</<li>", GetLabel("Account.CreateAccount.EmailWrongFromat"));

                if (Password != Confirmation)
                    _model.Message += String.Format("<li>{0}</<li>", GetLabel("Account.CreateAccount.PasswordNoMatch"));

                if ((Password != null && Password.Length > 0 && Password.Length < AppSession.PasswordMaxLength) ||
                (Confirmation != null && Confirmation.Length > 0 && Confirmation.Length < AppSession.PasswordMaxLength))
                {
                    _model.Message += String.Format("<li>{0}</<li>", String.Format(GetLabel("Account.CreateAccount.PasswordLength"), AppSession.PasswordMaxLength));
                }
            }

            // Check mandatory fields
            if (FieldInfo != null)
            {
                foreach (ProfileFieldInfo Field in FieldInfo)
                {
                    ProfileField profileField = ProfileFields.GetBy(int.Parse(Field.ID));
                    if (profileField.IsMandatory == 1 && (Field.Value == null || Field.Value.Trim().Length == 0))
                    {
                        _model.Message += String.Format("<li>{0}</li>", String.Format(GetLabel("Account.CreateAccount.Mandatory"), profileField.FieldName));
                    }

                    if (profileField.IsMandatory == 1 && profileField.FieldTypeID == ProfileFieldTypeEnum.CheckBox && Field.Value != null && Field.Value.ToLower() == "false")
                    {
                        _model.Message += String.Format("<li>{0}</li>", String.Format(GetLabel("Account.CreateAccount.Mandatory"), profileField.FieldName));
                    }
                }
            }

            bool nonAlphaNumeric = Name.Replace(" ", "").All(c => char.IsLetterOrDigit(c));
            if (!nonAlphaNumeric)
            {
                _model.Message += String.Format("<li>{0}</<li>", GetLabel("Account.CreateAccount.NameNonAlfaNum"));
            }

            if (_model.Message.Length > 0)
            {
                _model.Message = String.Format("<ul class=\"error-message-list\">{0}</ul>", _model.Message);
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;

                return Json(new
                {
                    Status = RequestResultInfoType.ErrorOrDanger,
                    NotifyType = NotifyType.DialogInline,
                    Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)

                }, JsonRequestBehavior.AllowGet);
            }

            // Check email format
            if (!AppSession.IsEmail(Email))
            {
                _model.Title = GetLabel("Account.Controller.Warning");
                _model.Message = GetLabel("Account.Controller.WrongEmail");
                _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                AuditEvent.AppEventError(AppParams.GeneralAdminEmail.Value, String.Format(AuditEvent.AccountWrongEmail, Name, Email));
            }
            else
            {
                if (!AppSession.IsMailDomainAllowed(Email))
                {
                    _model.Title = GetLabel("Account.Controller.Warning");
                    _model.Message = GetLabel("Account.Controller.DomainNotAllowed");
                    _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                    AuditEvent.AppEventError(AppParams.GeneralAdminEmail.Value, String.Format(AuditEvent.AccountDomainNotAllowed, Name, Email));
                }
                else
                {
                    Member Member = Members.GetByEmailOrName(Email, Name);

                    if (Member.MemberID > 0)
                    {
                        _model.Title = GetLabel("Account.Controller.Warning");
                        _model.Message = GetLabel("Account.Controller.AccountExists");
                        _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                        AuditEvent.AppEventError(AppParams.GeneralAdminEmail.Value, String.Format(AuditEvent.AccountAccountExists, Name, Email));
                    }
                    else
                    {
                        // Was account activated ?
                        // Was account blocked ?

                        Member member = new Logic.Objects.Member();
                        member.Name = Name;
                        member.Email = Email;
                        member.Password = Password;
                        member.IsBuiltIn = false;
                        member.Created = DateTime.UtcNow;

                        member.Save();

                        try
                        {
                            string ActivateToken = Web.Admin.Logic.StringTool.RandomString(20);

                            if (!SendActivationEmail(Name, Email, ActivateToken)){
                                throw new Exception("Creating an account notification e-mail has not been send!");
                            }

                            ActionToken actionToken = new ActionToken();
                            actionToken.Email = Email;
                            actionToken.Token = HttpUtility.UrlDecode(ActivateToken);
                            actionToken.ActionType = ActionTokenTypes.SelfActivation;
                            actionToken.ReturnURL = AppSession.ReturnUrl != null ? AppSession.ReturnUrl : ( AppSession.Parameters.RulesRedirectAfterLogout.Value != "" ? AppSession.Parameters.RulesRedirectAfterLogout.Value : "") ;
                            actionToken.Save();

                            if (member.MemberID > 0)
                            {
                                string[] RoleNames = AppParams.RegistrationMemberRegistrationToRoles.Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (String RoleName in RoleNames)
                                {
                                    Role role = Web.Admin.Logic.Collections.Roles.GetBy(RoleName.Trim());
                                    if (role.RoleID > 0)
                                    {
                                        MemberRole memberrole = new MemberRole();
                                        memberrole.MemberID = member.MemberID;
                                        memberrole.RoleID = role.RoleID;
                                        memberrole.Save();
                                    }
                                }
                            }

                            if (FieldInfo != null)
                            {
                                foreach (ProfileFieldInfo Field in FieldInfo)
                                {
                                    ProfileField profileField = ProfileFields.GetBy(int.Parse(Field.ID));

                                    MemberProfileField memberProfileField = new MemberProfileField();
                                    memberProfileField.MemberID = member.MemberID;
                                    memberProfileField.FieldID = int.Parse(Field.ID);
                                    memberProfileField.FieldValue = Field.Value;

                                    if (Field.Value == null || Field.Value.Trim().Length == 0)
                                        memberProfileField.Delete();
                                    else
                                        memberProfileField.Save();
                                }
                            }

                             Domain _domain = Domains.GetByName(AppSession.SignUpDomain);

                             if (_domain.DomainID > 0)
                              {
                                  MemberDomain _memberDomain = new MemberDomain();
                                  _memberDomain.DomainID = _domain.DomainID;
                                  _memberDomain.MemberID = member.MemberID;
                                  _memberDomain.Save();
                              }

                            if (AppSession.Parameters.RulesRedirectAfterSignUp.Value != null && AppSession.Parameters.RulesRedirectAfterSignUp.Value.Length > 0)
                                AfterSingUpRedirectUrl = AppSession.Parameters.RulesRedirectAfterSignUp.Value;

                            _model.Title = GetLabel("Account.Controller.Congrat");
                            _model.Message = GetLabel("Account.Controller.ActivationMailSent");
                            _model.InfoType = RequestResultInfoType.Success;
                            AuditEvent.AppEventSuccess(AppParams.GeneralAdminEmail.Value, String.Format(AuditEvent.AccountActivationMailSent, Name, Email));

                        }
                        catch (Exception ex) {
                            try
                            {
                                // Try to delete member if notification was failed.
                                member.Delete();
                            }
                            catch { }

                            _model.Title = GetLabel("Account.Controller.Warning");
                            _model.Message = GetLabel("Account.Controller.CantSendNotification");
                            _model.InfoType = RequestResultInfoType.ErrorOrDanger;
                            AuditEvent.AppEventError(Email ,"Registration: Something went wrong with e-mail notification: " + ex.Message, AuditEvent.GetSessionDetails(ex.StackTrace),true);
                        }
                    }
                }
            }

            return Json(new
               {
               Status = _model.InfoType,
               RedirectTo = AfterSingUpRedirectUrl,
               NotifyType = NotifyType.DialogInline,
               Html = this.RenderPartialView(@"_RequestResultDialogInLine", _model)

               }, JsonRequestBehavior.AllowGet);
        }
Пример #2
0
        public ActionResult SaveProfile(List <ProfileFieldInfo> FieldInfo, string TimeZoneID)
        {
            System.Threading.Thread.Sleep(1000);
            RequestResultModel _model = new RequestResultModel();

            _model.InfoType = RequestResultInfoType.ErrorOrDanger;
            _model.Message  = "";

            // Check mandatory fields
            foreach (ProfileFieldInfo Field in FieldInfo)
            {
                ProfileField profileField = ProfileFields.GetBy(int.Parse(Field.ID));
                if (profileField.IsMandatory == 1 && (Field.Value == null || Field.Value.Trim().Length == 0))
                {
                    _model.Message += String.Format("<li>{0}</li>", String.Format(GetLabel("Account.CreateAccount.Mandatory"), profileField.FieldName));
                }

                if (profileField.IsMandatory == 1 && profileField.FieldTypeID == ProfileFieldTypeEnum.CheckBox && Field.Value != null && Field.Value.ToLower() == "false")
                {
                    _model.Message += String.Format("<li>{0}</li>", String.Format(GetLabel("Account.CreateAccount.Mandatory"), profileField.FieldName));
                }
            }

            if (_model.Message.Length > 0)
            {
                _model.Message = String.Format("<ul class=\"error-message-list\">{0}</ul>", _model.Message);
                return(Json(new
                {
                    Status = RequestResultInfoType.ErrorOrDanger,
                    NotifyType = NotifyType.DialogInline,
                    Message = HttpUtility.HtmlDecode(this.RenderPartialView(@"_RequestResultPageInLine", _model))
                }, JsonRequestBehavior.AllowGet));
            }

            if (Profile.Member.TimeZoneID != TimeZoneID)
            {
                AuditEvent.AppEventInfo(AppSession.Profile.Member.Email, String.Format("Member updated time zone to: \"{0}\" ", Profile.Member.TimeZoneID));
            }

            Profile.Member.TimeZoneID = TimeZoneID;
            Profile.Member.UpdateTimeZone();

            String FieldValues = "";
            List <MemberProfileField> memberProfileFields = MemberProfileFields.GetByMember(Profile.Member.MemberID);

            foreach (ProfileFieldInfo Field in FieldInfo)
            {
                String Value = Field.Value != null?Field.Value.Trim() : Field.Value;

                ProfileField       profileField       = ProfileFields.GetBy(int.Parse(Field.ID));
                MemberProfileField memberProfileField = MemberProfileFields.GetField(memberProfileFields, int.Parse(Field.ID));

                if (profileField.Encrypted == 1 && memberProfileField.FieldValue != null && memberProfileField.FieldValue.Length > 0)
                {
                    memberProfileField.FieldValue = Encryptor.DecryptStringAES(memberProfileField.FieldValue, AppSession.EncryptionKey);
                }

                if (Value != memberProfileField.FieldValue)
                {
                    FieldValues += String.Format("<b>Name</b>:  {0} <b>Before:</b>  \"{1}\" <b>Now:</b>  \"{2}\"<br/>", profileField.FieldName, memberProfileField.FieldValue, Value);
                }

                memberProfileField.MemberID   = Profile.Member.MemberID;
                memberProfileField.FieldID    = int.Parse(Field.ID);
                memberProfileField.FieldValue = Value;

                if (profileField.Encrypted == 1 && memberProfileField.FieldValue != null && memberProfileField.FieldValue.Length > 0)
                {
                    memberProfileField.FieldValue = Encryptor.EncryptStringAES(memberProfileField.FieldValue, AppSession.EncryptionKey);
                }

                memberProfileField.Save();
            }

            memberProfileFields = MemberProfileFields.GetByMember(Profile.Member.MemberID);

            List <MemberFieldNameValue> MemberFieldNameValues = new List <MemberFieldNameValue>();

            foreach (MemberProfileField memberField in memberProfileFields)
            {
                MemberFieldNameValues.Add(new MemberFieldNameValue {
                    Name = memberField.ProfileFieldID.ToString(), Value = memberField.FieldValue, Type = (int)ProfileFields.GetBy(memberField.FieldID).FieldTypeID
                });
            }

            _model.Message  = "Your profile has been updated successfully.";
            _model.InfoType = RequestResultInfoType.Success;

            AuditEvent.AppEventInfo(AppSession.Profile.Member.Email, String.Format("Profile of \"{0}\" {1} member has been updated successfully.", AppSession.Profile.Member.Name, AppSession.Profile.Member.Email), AuditEvent.GetSessionDetails(FieldValues));

            return(Json(new
            {
                Status = RequestResultInfoType.Success,
                NotifyType = NotifyType.DialogInline,
                Message = HttpUtility.HtmlDecode(this.RenderPartialView(@"_RequestResultPageInLine", _model)),
                MemberFields = MemberFieldNameValues,
                TimeZoneID = Profile.Member.TimeZoneID != null && Profile.Member.TimeZoneID.Length > 0 ? Profile.Member.TimeZoneID : ""
            }, JsonRequestBehavior.AllowGet));
        }