Esempio n. 1
0
        private void btnEditRole_Click(object sender, EventArgs e)
        {
            UserLogic   userLogic  = new UserLogic();
            RoleLogic   roleLogic  = new RoleLogic();
            PortalLogin Login      = new PortalLogin();
            SingleUser  singleUser = new SingleUser();
            var         AllRoles   = roleLogic.RetrieveAllRoles();

            User U = new User(email);

            userLogic.GetSingleUser(U);

            if (U.RoleName == "Admin")
            {
                if (lbxRoles.SelectedIndex > -1)
                {
                    foreach (var OneRole in AllRoles)
                    {
                        if (OneRole.RetrieveRoleName() == lbxRoles.SelectedItem.ToString())
                        {
                            rolestring = Convert.ToString(lbxRoles.SelectedItem);
                            this.Hide();
                            SingleRole SingleRole = new SingleRole(OneRole.RetrieveRoleID(), rolestring, email);
                            SingleRole.Show();
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("U heeft hier de permissies niet voor!");
            }
        }
Esempio n. 2
0
        private void btn_logout_Click(object sender, EventArgs e)
        {
            this.Hide();
            var logout = new PortalLogin();

            logout.Closed += (s, args) => this.Close();
            logout.Show();
        }
Esempio n. 3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            var ipAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

            if (string.IsNullOrEmpty(ipAddress))
            {
                ipAddress = HttpContext.Current.Request.UserHostAddress;
            }

            var username = tbUsername.Text;
            var personID = PortalLogin.Authenticate(username, tbPassword.Text, ipAddress, CurrentOrganization.OrganizationID);

            if (personID != -1)
            {
                var login = new Login(username);
                FormsAuthentication.SetAuthCookie(login.LoginID, false);
                HttpContext.Current.Response.Cookies["portalroles"].Value = string.Empty;

                try
                {
                    var person       = new Person(personID);
                    var facebookUser = GetFacebookUser();
                    SavePersonAttribute(person, facebookUser["id"].ToString(), CurrentOrganization.OrganizationID);
                }
                catch (FacebookApiException ex)
                {
                    new ExceptionHistoryData().AddUpdate_Exception(ex, CurrentOrganization.OrganizationID,
                                                                   "Cccev.Web", ArenaContext.Current.ServerUrl);
                }

                Redirect();
            }

            lblLoginError.Text    = "Please enter a valid username and password.";
            lblLoginError.Visible = true;
        }
Esempio n. 4
0
        public PortalLoginDto UpdatePortalLogin(string id, string username, string password, IEnumerable <string> roleIds, bool isPasswordToChange, bool isPasswordChanged, bool isLocked)
        {
            var columnsCommand = @"
SELECT l.Id, l.Username, l.PasswordHash, l.IsPasswordToChange, l.CreatorId, l.CreationTime, l.EditorId, l.LastEditTime, l.IsValid,
  STUFF((
    SELECT ','+r.Name
    FROM PortalRoles r INNER JOIN PortalLoginRoles lr on lr.RoleId=r.Id
    WHERE lr.LoginId=l.Id
    FOR XML PATH('')
  ), 1, 1, '') as Roles";
            var queryCommand   = @"
FROM [PortalLogins] l
WHERE l.Id=@Id";

            using (var connection = GetConnection())
            {
                connection.Open();

                using (var transcation = connection.BeginTransaction())
                {
                    try
                    {
                        PortalLoginDto dto   = connection.Query <PortalLoginDto>($@"{columnsCommand} {queryCommand}", new { Id = id }, transcation).FirstOrDefault();
                        var            login = new PortalLogin()
                        {
                            Id                 = id,
                            Username           = username,
                            PasswordHash       = isPasswordChanged ? _passwordHasher.HashPassword(password) : dto.PasswordHash,
                            IsPasswordToChange = dto.IsPasswordToChange ? dto.IsPasswordToChange : isPasswordToChange,
                            IsLocked           = isLocked,
                            CreationTime       = DateTime.UtcNow,
                            CreatorId          = CurrentUserId,
                            EditorId           = CurrentUserId,
                            LastEditTime       = DateTime.UtcNow,
                            IsValid            = true,
                        };

                        connection.Update(login, transcation);

                        var existingRoles = connection.Query <PortalLoginRole>(@"SELECT * FROM PortalLoginRoles WHERE LoginId=@Id",
                                                                               new { Id = id }, transcation);

                        var roles    = existingRoles.Select(r => r.RoleId);
                        var toAdd    = roleIds.Where(r => !roles.Contains(r));
                        var toRemove = existingRoles.Where(r => !roleIds.Contains(r.RoleId));

                        foreach (var r in toAdd)
                        {
                            var role = new PortalLoginRole()
                            {
                                LoginId = login.Id,
                                RoleId  = r
                            };
                            connection.Insert(role, transcation);
                        }

                        foreach (var r in toRemove)
                        {
                            connection.Delete(r, transcation);
                        }



                        dto = connection.Query <PortalLoginDto>($@"{columnsCommand} {queryCommand}", new { Id = id }, transcation).FirstOrDefault();

                        transcation.Commit();

                        return(dto);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e.Message);
                        transcation.Rollback();
                        return(null);
                    }
                }
            }
        }
Esempio n. 5
0
        public PortalLoginDto CreatePortalLogin(string username, string password, IEnumerable <string> roleIds, bool isPasswordToChange)
        {
            var login = new PortalLogin()
            {
                Id                 = IdHelper.NewId(),
                Username           = username,
                PasswordHash       = _passwordHasher.HashPassword(password),
                IsPasswordToChange = isPasswordToChange,
                IsLocked           = false,
                CreationTime       = DateTime.UtcNow,
                CreatorId          = CurrentUserId,
                EditorId           = null,
                LastEditTime       = null,
                IsValid            = true,
            };

            var columnsCommand = @"
SELECT l.Id, l.Username, l.PasswordHash, l.IsPasswordToChange, l.CreatorId, l.CreationTime, l.EditorId, l.LastEditTime, l.IsValid,
  STUFF((
    SELECT ','+r.Name
    FROM PortalRoles r INNER JOIN PortalLoginRoles lr on lr.RoleId=r.Id
    WHERE lr.LoginId=l.Id
    FOR XML PATH('')
  ), 1, 1, '') as Roles";
            var queryCommand   = @"
FROM [PortalLogins] l
WHERE l.Id=@Id";

            using (var connection = GetConnection())
            {
                connection.Open();

                using (var transcation = connection.BeginTransaction())
                {
                    try
                    {
                        connection.Insert(login, transcation);
                        foreach (var r in roleIds)
                        {
                            var role = new PortalLoginRole()
                            {
                                LoginId = login.Id,
                                RoleId  = r
                            };
                            connection.Insert(role, transcation);
                        }

                        var dto = connection.QueryFirstOrDefault <PortalLoginDto>($@"{columnsCommand} {queryCommand}", new { Id = login.Id }, transcation);

                        transcation.Commit();

                        return(dto);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e.Message);
                        transcation.Rollback();
                        return(null);
                    }
                }
            }
        }