phpScheduleIt
May 19, 2013, 11:55:25 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: phpScheduleIt 2.4.2 has been released!
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: default group  (Read 733 times)
kordan
Jr. Member
**

Karma: 0
Posts: 53


« on: March 21, 2012, 03:33:00 AM »

Is it possible to automatically join a newly created account to a default group?
Thanks in advance.
Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5403


WWW
« Reply #1 on: March 23, 2012, 05:21:57 PM »

Not out of the box, but you could easily change the registration code to add the user to the group of your choice. I'll add this as an option for a future version.
Logged
fifthgear
Newbie
*

Karma: 0
Posts: 3


« Reply #2 on: March 25, 2012, 09:03:18 PM »

Could you advise how ? Lets say I have a group called Users
Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5403


WWW
« Reply #3 on: March 27, 2012, 02:02:22 PM »

In /lib/Application/Authentication/Registration.php you'll want to change the Register() function to also call

Code:
$groupId = fill in your group id here;
ServiceLocator::GetDatabase()->ExecuteInsert(new AddUserGroupCommand($userId, $groupId));
Logged
kordan
Jr. Member
**

Karma: 0
Posts: 53


« Reply #4 on: April 18, 2012, 03:53:32 AM »

Ciao Nick,
I changed the the function Register in /lib/Application/Authentication/Registration.php as follow,

    public function Register($username, $email, $firstName, $lastName, $password, $timezone, $language,
                             $homepageId,
                             $additionalFields = array())
    {
        $encryptedPassword = $this->_passwordEncryption->EncryptPassword($password);

        $attributes = new UserAttribute($additionalFields);

        $registerCommand = new RegisterUserCommand($username, $email, $firstName, $lastName,
            $encryptedPassword->EncryptedPassword(), $encryptedPassword->Salt(), $timezone, $language, $homepageId,
            $attributes->Get(UserAttribute::Phone), $attributes->Get(UserAttribute::Organization), $attributes->Get(UserAttribute::Position),
            AccountStatus::ACTIVE);

        $db = ServiceLocator::GetDatabase();
        $userId = $db->ExecuteInsert($registerCommand);
        $this->AutoAssignPermissions($userId);

        $groupName = 'PRO'; //<-- default group name
        $reader = $db->Query(new GetGroupByNameCommand($groupName));
        if ($row = $reader->GetRow())
        {
            $group = new Group($row[ColumnNames::GROUP_ID], $row[ColumnNames::GROUP_NAME]);
            $groupId = $group->Id();
            $db->ExecuteInsert(new AddUserGroupCommand($userId, $groupId));
        }
        $reader->Free();
    }

but when an Ldap user logs in FOR THE FIRST TIME the front page doesn't reload. The perceived output is a blank page. Once refreshed the browser page, the Ldap user understand he/she is inside phpScheduleIt BUT he/she does not belong to the "PRO" group.

Before closing I need to add that I also made the following two additions:
1. to /lib/Database/Commands/Commands.php
class GetGroupByNameCommand extends SqlCommand
{
    public function __construct($groupName)
    {
        parent::__construct(Queries::GET_GROUP_BY_NAME);
        $this->AddParameter(new Parameter(ParameterNames::GROUP_NAME, $groupName));
    }
}

2. to /lib/Database/Commands/DataConstant.php
    const GET_GROUP_BY_NAME =
            'SELECT *
        FROM groups
        WHERE name = @groupname';

Can I ask for an help, please?
Thanks in advance.
Logged
kordan
Jr. Member
**

Karma: 0
Posts: 53


« Reply #5 on: April 18, 2012, 04:34:50 AM »

Sorry Nick.
As usual, after hours once asked the solution arrives in a minute!
Fixed. It was a typo.
Logged
Nut65
Newbie
*

Karma: 0
Posts: 7


« Reply #6 on: May 12, 2012, 01:11:50 PM »

Thanks kordan, worked like a charm!
Logged
kordan
Jr. Member
**

Karma: 0
Posts: 53


« Reply #7 on: May 15, 2012, 01:43:16 AM »

cool! Happy for this Nut65.  Smiley
Logged
chaplib
Newbie
*

Karma: 0
Posts: 20


« Reply #8 on: July 09, 2012, 05:27:41 PM »

What was the typo??
Logged
chaplib
Newbie
*

Karma: 0
Posts: 20


« Reply #9 on: July 09, 2012, 05:36:08 PM »

I figured it our.
Logged
SYB
Newbie
*

Karma: 0
Posts: 31


« Reply #10 on: July 18, 2012, 03:22:30 PM »

Thanks for your answers, I was able to make this work in v2.2.2 by following Nick' suggestion.

I've added his code at line 72 in /lib/Application/Authentication/Registration.php

Quote
$groupId = 7;
        ServiceLocator::GetDatabase()->ExecuteInsert(new AddUserGroupCommand($userId, $groupId));

Thanks again  Smiley
Logged
kordan
Jr. Member
**

Karma: 0
Posts: 53


« Reply #11 on: July 19, 2012, 01:59:49 AM »

Nick can you include this feature in next releases, please?
Thanks in advance.
Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5403


WWW
« Reply #12 on: July 23, 2012, 01:51:13 PM »

Default groups are on my list. Not sure if it will make 2.3 or not. 2.2 did introduce a PostRegistration plugin. This will allow you to write a plugin to accomplish this without changing the code.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2006-2007, Simple Machines Valid XHTML 1.0! Valid CSS!