Exemplo n.º 1
0
        public bool? CreateAccount(User user)
        {
            user.Inactive = false;
            user.Role = UserRoles.User;
            user.Password = this.EncryptPassword(user.Password);

            bool? validation = this.RegisterValidation(user);
            bool? result;
            switch (validation)
            {
                case true:
                    result =  this._userRepository.InsertUser(user);
                    break;
                case false:
                    result = false;
                    break;
                case null:
                    result = null;
                    break;
                default:
                    result = false;
                    break;
            }
            return result;
        }
Exemplo n.º 2
0
        public ActionResult Register(RegisterModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = new User();
                user.Login = model.UserName;
                user.FirstName = model.FirstName;
                user.SurName = model.LastName;
                user.Password = model.Password;
                user.Mail = model.Email;

                bool? createAccount = this._securityManager.CreateAccount(user);
                if (createAccount == true)
                {
                    return Redirect(returnUrl ?? Url.Action("Index", "Home"));
                }
                else if(createAccount == false)
                {
                    ModelState.AddModelError("", "There is some user with same login");
                    return View();
                }
                else
                {
                    ModelState.AddModelError("", "There is some user with same email");
                    return View();
                }
             }
            else
             {
                 ModelState.AddModelError("", "Incorrect data");
                 return View();
             }
        }
Exemplo n.º 3
0
        private bool? RegisterValidation(User user)
        {
            if (!this._userRepository.IsLoginValid(user.Login))
            {
                if(!this._userRepository.IsMailValid(user.Mail))
                {
                    return true;
                }
                else
                {
                    return null;
                }

            }
            else
            {
                return false;
            }
        }
Exemplo n.º 4
0
        public bool UpdateUserInfo(User user)
        {
            if (!this.IsNameValid(user.FirstName, true) ||
                !this.IsNameValid(user.SurName, false) ||
                !this.IsPhoneValid(user.Phone) ||
                !this.IsMailValid(user.Mail))
            {
                return false;
            }

            return this._userRepository.UpdateUserById(user);
        }
Exemplo n.º 5
0
 public void Update(User user)
 {
     //Update user info
 }
Exemplo n.º 6
0
        protected void GridViewUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var user = new User();
            GridViewRow row = this.GridViewUsers.Rows[e.RowIndex];

            user.Id = Convert.ToInt32(((Label)this.GridViewUsers.Rows[e.RowIndex].FindControl("lblUserIdu")).Text);
            user.Login = ((Label)this.GridViewUsers.Rows[e.RowIndex].FindControl("lblUserLoginu")).Text;
            user.FirstName = ((TextBox)this.GridViewUsers.Rows[e.RowIndex].FindControl("txtUserNameu")).Text;
            user.SurName = ((TextBox)this.GridViewUsers.Rows[e.RowIndex].FindControl("txtUserSurnameu")).Text;
            user.Role = (UserRoles)(Enum.Parse(typeof(UserRoles),
                ((DropDownList)this.GridViewUsers.Rows[e.RowIndex].FindControl("ddlUserRole")).SelectedValue));
            user.Phone = ((TextBox)this.GridViewUsers.Rows[e.RowIndex].FindControl("txtPhoneu")).Text;
            user.Mail = ((TextBox)this.GridViewUsers.Rows[e.RowIndex].FindControl("txtMailu")).Text;
            user.Birthday = Convert.ToDateTime(((TextBox)this.GridViewUsers.Rows[e.RowIndex].FindControl("txtBirthdayu")).Text);
            user.AboutMe = ((TextBox)this.GridViewUsers.Rows[e.RowIndex].FindControl("txtAboutu")).Text;

            var role = User.IsInRole(UserRoles.Administrator.ToString()) ?
               UserRoles.Administrator : UserRoles.Master;

            if ((int) role <= (int) user.Role)
            {
                String permission = String.Empty;
                String alert = String.Empty;
                if (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName == "en")
                {
                    permission = "Rights restriction";
                    alert = "You do not have appropriate rights";
                }

                else
                {
                    permission = "Обмеження прав";
                    alert = "У вас немає належних прав";
                }

                ScriptManager.RegisterStartupScript(this, typeof(Page), "", "<script>alert('" + alert + "');</script>", false);
                this.GridViewUsers.EditIndex = -1;
            }
            else
            {
                var usersManager = new UsersManager(new UserRepository(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString));
                usersManager.UpdateUserInfo(user);

                this.GridViewUsers.EditIndex = -1;

            }
        }