Esempio n. 1
0
 protected void btnChangePassword_Click(object sender, EventArgs e)
 {
     if (IsLoggedIn)
     {
         IAccessManagementService ams    = new AccessManagementService();
         Result <OlescUser>       result = ams.ChangePassword(CurrentUser.Email, txtPassword.Text);
         if (result.isSuccess)
         {
             txtPassword.Text                 = string.Empty;
             txtConfirmPassword.Text          = string.Empty;
             cvSuccessMessageSummary.CssClass = "alert-success";
         }
         else
         {
             cvSuccessMessageSummary.CssClass = "alert-danger";
         }
         cvSuccessMessageSummary.Text    = result.message;
         cvSuccessMessageSummary.IsValid = false;
     }
 }
Esempio n. 2
0
        protected void liUserLogin_Authenticate(object sender, AuthenticateEventArgs e)
        {
            IAccessManagementService ams    = new AccessManagementService();
            Result <OlescUser>       result = ams.Login(liUserLogin.UserName, liUserLogin.Password);

            if (result.isSuccess)
            {
                CurrentUser = result.resultObject;
                //If Remember me is set
                if (liUserLogin.RememberMeSet)
                {
                    // Clear any other tickets that are already in the response
                    Response.Cookies.Clear();

                    // Set the new expiry date - to thirty days from now
                    DateTime expiryDate = DateTime.Now.AddDays(30);

                    // Create a new forms auth ticket
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(2, liUserLogin.UserName, DateTime.Now, expiryDate, true, liUserLogin.Password);

                    // Encrypt the ticket
                    string encryptedTicket = FormsAuthentication.Encrypt(ticket);

                    // Create a new authentication cookie - and set its expiration date
                    HttpCookie authenticationCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    authenticationCookie.Expires = ticket.Expiration;

                    // Add the cookie to the response.
                    Response.Cookies.Add(authenticationCookie);
                }
            }
            else
            {
                CurrentUser = null;
            }
            e.Authenticated = result.isSuccess;
        }
 public AuthenticationController(AccessManagementService accessManagementService)
 {
     _accessManagementService = accessManagementService;
 }
Esempio n. 4
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            //Validate Selections for student
            if (chkRoles.Items[0].Selected)
            {
                if (string.IsNullOrEmpty(ddlMajors.SelectedItem.Value))
                {
                    rfvMajor.IsValid = false;
                }
                else
                {
                    rfvMajor.IsValid = true;
                }

                if (string.IsNullOrEmpty(ddlCollege.SelectedItem.Value))
                {
                    rfvCollege.IsValid = false;
                }
                else
                {
                    rfvCollege.IsValid = true;
                }
            }
            else
            {
                rfvMajor.IsValid   = true;
                rfvCollege.IsValid = true;
            }

            if (rfvMajor.IsValid && rfvCollege.IsValid)
            {
                AccessManagementService AccMng = new AccessManagementService();

                OlescUser        newUser        = new OlescUser();
                UserProfile      newUserProfile = new UserProfile();
                List <OlescRole> role           = new List <OlescRole>();

                newUser.Email    = txtEmail.Text;
                newUser.Password = txtPassword.Text;

                newUserProfile.FirstName = txtFirstName.Text;
                newUserProfile.LastName  = txtLastName.Text;
                newUserProfile.College   = ddlCollege.SelectedItem.Text;
                newUserProfile.Major     = ddlMajors.SelectedItem.Text;

                /* 2 fot now only testing, should change (2 is Student)*/
                //role.Add(new DAL.role() { ID = int.Parse(radRole.SelectedValue) };
                role = chkRoles.Items
                       .Cast <ListItem>()
                       .Where(ci => ci.Selected)
                       .Select(ci => new OlescRole()
                {
                    ID = int.Parse(ci.Value)
                })
                       .ToList();

                // If registration
                Result <OlescUser> result = AccMng.Register(newUser, newUserProfile, role);

                if (result.isSuccess)
                {
                    UrlUtility.Redirect(WebsitePages.REGISTRATION_PAGE, "success");
                }
                else
                {
                }
            }
        }