Example #1
0
        protected void loginForm_Authenticate(object sender, AuthenticateEventArgs e)
        {
            var userLogin = this.loginForm.UserName;
            var userPassword = this.loginForm.Password;
            var rememberUser = this.loginForm.RememberMeSet;

            //read data from repository
            var userManager = new UsersManager(new UserRepository(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString));
            var userRoles = userManager.UserAuthentication(userLogin, userPassword);
            if (userRoles != null)
            {
                // Create forms authentication ticket
                var ticket = new FormsAuthenticationTicket(
                    1,
                    userLogin,
                    DateTime.Now,
                    DateTime.Now.AddMinutes(10),
                    rememberUser,
                    userRoles,
                    FormsAuthentication.FormsCookiePath);

                var hash = FormsAuthentication.Encrypt(ticket);
                var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);

                if (ticket.IsPersistent)
                {
                    cookie.Expires = ticket.Expiration;
                }

                // Add the cookie to the response
                this.Response.Cookies.Add(cookie);

                var returnUrl = this.Request.QueryString["ReturnUrl"] ?? "~/Secure/AdminPage.aspx";

                this.Response.Redirect(returnUrl);

            }
        }
Example #2
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;

            }
        }
Example #3
0
        protected void btnLockUsers_Click(object sender, EventArgs e)
        {
            var manager = new UsersManager(new UserRepository(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString));
            var role = User.IsInRole(UserRoles.Administrator.ToString()) ?
                UserRoles.Administrator : UserRoles.Master;

            manager.UsersLock(CheckedList(), role);
        }
Example #4
0
 protected void btnUnlockUser_Click(object sender, EventArgs e)
 {
     var manager = new UsersManager(new UserRepository(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString));
     manager.UsersUnlock(CheckedList());
 }