public function php($data)
 {
     $member = $this->member;
     $valid = true;
     foreach ($this->unique as $field) {
         $other = DataObject::get_one('Member', sprintf('"%s" = \'%s\'', Convert::raw2sql($field), Convert::raw2sql($data[$field])));
         if ($other && (!$this->member || !$this->member->exists() || $other->ID != $this->member->ID)) {
             $fieldInstance = $this->form->Fields()->dataFieldByName($field);
             if ($fieldInstance->getCustomValidationMessage()) {
                 $message = $fieldInstance->getCustomValidationMessage();
             } else {
                 $message = sprintf(_t('MemberProfiles.MEMBERWITHSAME', 'There is already a member with the same %s.'), $field);
             }
             $valid = false;
             $this->validationError($field, $message, 'required');
         }
     }
     // Create a dummy member as this is required for custom password validators
     if (isset($data['Password']) && $data['Password'] !== "") {
         if (is_null($member)) {
             $member = Member::create();
         }
         if ($validator = $member::password_validator()) {
             $results = $validator->validate($data['Password'], $member);
             if (!$results->valid()) {
                 $valid = false;
                 foreach ($results->messageList() as $key => $value) {
                     $this->validationError('Password', $value, 'required');
                 }
             }
         }
     }
     return $valid && parent::php($data);
 }
示例#2
0
 /**
  * This function create member
  * when data posted from 
  * /admin/member/create
  */
 public function postCreate()
 {
     // Check validation
     $validator = Validator::make(Input::all(), Member::$rulesForCreate, Member::$messages);
     // If failed then redirect to member-create-get route with
     // validation error and input old
     if ($validator->fails()) {
         return Redirect::route('member-create-get')->withErrors($validator)->withInput();
     }
     // If validation is not failed then create member
     $member = Member::create(array('first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'age' => Input::get('age'), 'gender' => Input::get('gender'), 'DOB' => DateFormat::store(Input::get('DOB')), 'present_address' => Input::get('present_address'), 'permanent_address' => Input::get('permanent_address'), 'city' => Input::get('city'), 'state' => Input::get('state'), 'country' => Input::get('country'), 'mobile_no' => Input::get('mobile_no'), 'email' => Input::get('email'), 'created_by' => Session::get('username')));
     // Also create user account for the member
     $user = User::create(array('details_id' => $member->id, 'username' => Input::get('username'), 'email' => $member->email, 'user_level' => 'member', 'active' => 0));
     // generate random code and password
     $password = str_random(10);
     $code = str_random(60);
     $newHashPassword = Hash::make($password);
     // Save new password and code
     $user->password_tmp = $newHashPassword;
     $user->activation_code = $code;
     if ($user->save()) {
         // Send email to the member.
         // This email contains username,password,activation link
         Mail::send('emails.auth.activation', array('first_name' => $member->first_name, 'last_name' => $member->last_name, 'username' => $user->username, 'password' => $password, 'activation_link' => URL::route('activation-get', $code)), function ($message) use($user) {
             $message->to($user->email, $user->username)->subject('Confirm Activation');
         });
     }
     return View::make('adminArea.member.create')->with('success', 'Activation link has been sent successfully');
 }
 public function validateData(Order $order, array $data)
 {
     if (Member::currentUserID()) {
         return;
     }
     $result = ValidationResult::create();
     if (Checkout::membership_required() || !empty($data['Password'])) {
         $member = Member::create($data);
         $idfield = Member::config()->unique_identifier_field;
         $idval = $data[$idfield];
         if (ShopMember::get_by_identifier($idval)) {
             // get localized field labels
             $fieldLabels = $member->fieldLabels(false);
             // if a localized value exists, use this for our error-message
             $fieldLabel = isset($fieldLabels[$idfield]) ? $fieldLabels[$idfield] : $idfield;
             $result->error(sprintf(_t("Checkout.MEMBEREXISTS", "A member already exists with the %s %s"), $fieldLabel, $idval), $idval);
         }
         $passwordresult = $this->passwordvalidator->validate($data['Password'], $member);
         if (!$passwordresult->valid()) {
             $result->error($passwordresult->message(), "Password");
         }
     }
     if (!$result->valid()) {
         throw new ValidationException($result);
     }
 }
 public function parseOrderCustomer($orders, $transaction)
 {
     foreach ($orders->transactions->transaction as $order) {
         // if not a guest transaction in FoxyCart
         if (isset($order->customer_email) && $order->is_anonymous == 0) {
             // if Customer is existing member, associate with current order
             if (Member::get()->filter('Email', $order->customer_email)->First()) {
                 $customer = Member::get()->filter('Email', $order->customer_email)->First();
             } else {
                 // set PasswordEncryption to 'none' so imported, encrypted password is not encrypted again
                 Config::inst()->update('Security', 'password_encryption_algorithm', 'none');
                 // create new Member, set password info from FoxyCart
                 $customer = Member::create();
                 $customer->Customer_ID = (int) $order->customer_id;
                 $customer->FirstName = (string) $order->customer_first_name;
                 $customer->Surname = (string) $order->customer_last_name;
                 $customer->Email = (string) $order->customer_email;
                 $customer->Password = (string) $order->customer_password;
                 $customer->Salt = (string) $order->customer_password_salt;
                 $customer->PasswordEncryption = 'none';
                 // record member record
                 $customer->write();
             }
             // set Order MemberID
             $transaction->MemberID = $customer->ID;
         }
     }
 }
示例#5
0
 public function run()
 {
     $faker = Faker\Factory::create();
     //
     for ($i = 0; $i < 50; $i++) {
         $user = Member::create(array('first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'slug' => $faker->slug, 'image' => $faker->imageUrl($width = 125, $height = 150), 'pob' => $faker->city, 'dob' => $faker->date('Y-m-d', 'now'), 'gender' => $faker->numberBetween(1, 2), 'email' => $faker->email, 'address' => $faker->address, 'city' => $faker->city, 'province' => $faker->state, 'phone_home' => $faker->phoneNumber, 'phone_mobile' => $faker->phoneNumber));
     }
 }
 public function setUpOnce()
 {
     parent::setUpOnce();
     Member::create(array('Email' => '*****@*****.**', 'Password' => 'admin'))->write();
     $member = Member::get()->filter(array('Email' => '*****@*****.**'))->first();
     $member->addToGroupByCode('restfulapi-administrators');
     Member::create(array('Email' => '*****@*****.**', 'Password' => 'stranger'))->write();
 }
 public function doSignup(array $data)
 {
     $o_Member = Member::create();
     $this->saveInto($o_Member);
     $o_Member->Locale = i18n::get_locale();
     $o_Member->write();
     // We use Email Verified Member
     $this->controller->redirect('Security/emailsent/' . $data['Email']);
 }
 public static function authenticate($RAW_data, Form $form = null)
 {
     $member = Member::get()->first();
     if (!$member || !$member->exists()) {
         $member = Member::create();
         $member->FirstName = _t('Member.DefaultAdminFirstname', 'Default Admin');
         $member->write();
     }
     return $member;
 }
 /**
  * @param array $data
  * @return Member
  */
 public function buildReduced(array $data)
 {
     $member = Member::create();
     $member->FirstName = trim($data['FirstName']);
     $member->Surname = trim($data['Surname']);
     $member->Email = trim($data['Email']);
     $member->Country = trim($data['Country']);
     $member->Password = trim($data['Password']['_Password']);
     return $member;
 }
示例#10
0
 public function createMember()
 {
     $member = Member::create(array('first_name' => 'Iftekher', 'last_name' => 'Sunny', 'age' => 23, 'gender' => 'Male', 'DOB' => Carbon::today(), 'present_address' => 'Present address .....', 'permanent_address' => 'Permanent address ...', 'city' => 'Chittagong', 'state' => 'state ....', 'country' => 'Bangladesh', 'mobile_no' => '+8801800000000', 'email' => '*****@*****.**', 'created_by' => 'Developer'));
     $user = User::create(array('username' => 'member', 'password' => Hash::make('member'), 'user_level' => 'member123', 'email' => '*****@*****.**', 'password_tmp' => '', 'activation_code' => '', 'active' => 1, 'remember_token' => '', 'details_id' => $member->id));
     // generate random code and password
     $password = str_random(10);
     $code = str_random(60);
     $newHashPassword = Hash::make($password);
     // Save new password and code
     $user->password_tmp = $newHashPassword;
     $user->activation_code = $code;
     $user->save();
 }
 public function testUnchangedFieldsDoesNotTriggerStatusChange()
 {
     $spammer = Member::create();
     $spammer->Nickname = 'loveguru69';
     $spammer->FirstName = 'LoveGuru';
     $spammer->Occupation = 'Astrology';
     $spammer->Company = 'vashikaran specialist mantra';
     $spammer->Email = '*****@*****.**';
     $spammer->write();
     $user = Member::get()->filter('Nickname', 'loveguru69')->first();
     $this->assertEquals($user->ForumStatus, 'Ghost');
     $this->assertEmailSent('*****@*****.**', '*****@*****.**', 'Suspected spammer: Please review');
     $user->ForumStatus = 'Normal';
     $user->write();
     $this->assertEquals($user->ForumStatus, 'Normal');
 }
 public function parameterFields()
 {
     $member = Member::currentUserID() ? Member::currentUser() : Member::create();
     $dateformat = $member->getDateFormat();
     $fields = FieldList::create($start = DateField::create("StartPeriod", "Start Date"), $end = DateField::create("EndPeriod", "End Date"));
     if ($this->grouping) {
         $fields->push(DropdownField::create("Grouping", "Group By", array("Year" => "Year", "Month" => "Month", "Day" => "Day"), 'Month'));
         if (self::config()->display_uncategorised_data) {
             $fields->push(CheckboxField::create("IncludeUncategorised", "Include Uncategorised Data")->setDescription("Display data that doesn't have a date."));
         }
     }
     $start->setConfig("dateformat", $dateformat);
     $end->setConfig("dateformat", $dateformat);
     $start->setConfig("showcalendar", true);
     $end->setConfig("showcalendar", true);
     return $fields;
 }
 public function testUserFollowing()
 {
     Restrictable::set_enabled(false);
     $memberOne = Member::create();
     $memberOne->Email = '*****@*****.**';
     $memberOne->Password = '******';
     $memberOne->write();
     $memberTwo = Member::create();
     $memberTwo->Email = '*****@*****.**';
     $memberTwo->Password = '******';
     $memberTwo->write();
     $svc = singleton('MicroBlogService');
     /* @var $svc MicroBlogService */
     singleton('SecurityContext')->setMember($memberOne);
     $svc->addFriendship($memberOne, $memberTwo);
     // gah - ss3's testing setup needs to be better sorted to be able to do this bit...
 }
 /**
  * @param $data
  * @param $form
  * @return bool|SS_HTTPResponse
  */
 public function Register($data, $form)
 {
     /** @var Form $form */
     $data = $form->getData();
     /** Set session array individually as setting the password breaks the form. */
     $sessionArray = array('Email' => $data['Email']);
     /** Check for existing member email address */
     if ($existingUser = DataObject::get_one('Member', "Email = '" . Convert::raw2sql($data['Email']) . "'")) {
         $form->AddErrorMessage('Email', 'Sorry, that email address already exists. Please choose another.', 'validation');
         Session::set('FormInfo.Form_' . $this->name . '.data', $sessionArray);
         return $this->controller->redirectBack();
     }
     /** Otherwise create new member and log them in
      *
      * @var Member $member
      */
     $member = Member::create();
     $form->saveInto($member);
     $member->write();
     $member->login();
     /** Find or create the 'user' group
      *
      * @var Group $userGroup
      */
     if (!($userGroup = DataObject::get_one('Group', "Code = 'users'"))) {
         $userGroup = Group::create();
         $userGroup->Code = 'users';
         $userGroup->Title = 'Users';
         $userGroup->Write();
         $userGroup->Members()->add($member);
     }
     /** Add member to user group */
     $userGroup->Members()->add($member);
     /** Get profile page otherwise display warning. */
     if ($ProfilePage = DataObject::get_one('EditProfilePage')) {
         $this->controller->setFlash('Welcome ' . $data['Email'] . ', your account has been created!', 'success');
         return $this->controller->redirect($ProfilePage->Link());
     } else {
         $this->controller->setFlash('Please add a "Edit Profile Page" in your SiteTree to enable profile editing', 'warning');
         return $this->controller->redirect(Director::absoluteBaseURL());
     }
 }
 public function register($data, $form)
 {
     //log out existing user
     if ($member = Member::currentUser()) {
         $member->logOut();
     }
     $member = Member::create();
     $form->saveInto($member);
     $member->write();
     $this->extend('onRegister', $member);
     $member->logIn();
     if ($back = Session::get("BackURL")) {
         Session::clear("BackURL");
         return $this->Controller()->redirect($back);
     }
     if ($link = $member->getProfileLink()) {
         return $this->controller->redirect($link);
     }
     return $this->controller->redirect($this->controller->Link());
 }
示例#16
0
 /**
  * @param array $data
  * @return Member
  */
 public function build(array $data)
 {
     $member = Member::create();
     $member->FirstName = trim($data['FirstName']);
     $member->Surname = trim($data['Surname']);
     $member->Email = trim($data['Email']);
     $gender = $data['Gender'];
     if ($gender != 'Male' && $gender != 'Female' && $gender != 'Prefer not to say') {
         $member->Gender = $data['GenderSpecify'];
     } else {
         $member->Gender = trim($gender);
     }
     $member->StatementOfInterest = trim($data['StatementOfInterest']);
     $member->Address = trim($data['Address']);
     $member->Suburb = trim($data['Suburb']);
     $member->City = trim($data['City']);
     $member->State = trim($data['State']);
     $member->Postcode = trim($data['Postcode']);
     $member->Country = trim($data['Country']);
     $member->Password = trim($data['Password']['_Password']);
     return $member;
 }
 /**
  * Create member account from data array.
  * Data must contain unique identifier.
  *
  * @throws ValidationException
  *
  * @param $data - map of member data
  *
  * @return Member|boolean - new member (not saved to db), or false if there is an error.
  */
 public function create($data)
 {
     $result = ValidationResult::create();
     if (!Checkout::member_creation_enabled()) {
         $result->error(_t("Checkout.MembershipIsNotAllowed", "Creating new memberships is not allowed"));
         throw new ValidationException($result);
     }
     $idfield = Config::inst()->get('Member', 'unique_identifier_field');
     if (!isset($data[$idfield]) || empty($data[$idfield])) {
         $result->error(_t('Checkout.IdFieldNotFound', 'Required field not found: {IdentifierField}', 'Identifier is the field that holds the unique user-identifier, commonly this is \'Email\'', array('IdentifierField' => $idfield)));
         throw new ValidationException($result);
     }
     if (!isset($data['Password']) || empty($data['Password'])) {
         $result->error(_t("Checkout.PasswordRequired", "A password is required"));
         throw new ValidationException($result);
     }
     $idval = $data[$idfield];
     if ($member = ShopMember::get_by_identifier($idval)) {
         // get localized field labels
         $fieldLabels = $member->fieldLabels(false);
         // if a localized value exists, use this for our error-message
         $fieldLabel = isset($fieldLabels[$idfield]) ? $fieldLabels[$idfield] : $idfield;
         $result->error(_t('Checkout.MemberExists', 'A member already exists with the {Field} {Identifier}', '', array('Field' => $fieldLabel, 'Identifier' => $idval)));
         throw new ValidationException($result);
     }
     $member = Member::create(Convert::raw2sql($data));
     // 3.2 changed validate to protected which made this fall through the DataExtension and error out
     $validation = $member->hasMethod('doValidate') ? $member->doValidate() : $member->validate();
     if (!$validation->valid()) {
         //TODO need to handle i18n here?
         $result->error($validation->message());
     }
     if (!$result->valid()) {
         throw new ValidationException($result);
     }
     return $member;
 }
 public function getuser()
 {
     $response = false;
     if (isset($_GET)) {
         $var = Convert::raw2xml(array_keys($_GET)[1]);
         if ($var == 'rug') {
             $getfield = "?nat=au";
             $isLego = false;
         } elseif ($var == 'lego') {
             $getfield = "?lego";
             $isLego = true;
         } else {
             $getfield = false;
         }
         if ($getfield) {
             $request = "http://api.randomuser.me/" . $getfield;
             $curl = curl_init($request);
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
             $response = json_decode(curl_exec($curl), true);
         }
         if ($response) {
             $newmember = Member::create();
             $newmember->setField('FirstName', ucfirst($response['results']['0']['user']['name']['first']));
             $newmember->setField('Surname', ucfirst($response['results']['0']['user']['name']['last']));
             $newmember->setField('Email', $response['results']['0']['user']['email']);
             $newmember->setField('Username', $response['results']['0']['user']['username']);
             $newmember->setField('Lego', $isLego);
             $newmember->ThumbnailID = $this->grabRUGImage($response, $newmember, 'thumbnail', 7);
             $newmember->LargeID = $this->grabRUGImage($response, $newmember, 'large', 132);
             $newmember->write();
             $newmember->addToGroupByCode('RUGUsers');
             Session::set('ActionStatus', 'success');
             Session::set('ActionMessage', 'New user successfully added!');
         }
     }
     return $this->redirectBack('/');
 }
 /**
  * Create member account from data array.
  * Data must contain unique identifier.
  *
  * @throws ValidationException
  *
  * @param $data - map of member data
  *
  * @return Member|boolean - new member (not saved to db), or false if there is an error.
  */
 public function create($data)
 {
     $result = ValidationResult::create();
     if (!Checkout::member_creation_enabled()) {
         $result->error(_t("Checkout.MEMBERSHIPSNOTALLOWED", "Creating new memberships is not allowed"));
         throw new ValidationException($result);
     }
     $idfield = Config::inst()->get('Member', 'unique_identifier_field');
     if (!isset($data[$idfield]) || empty($data[$idfield])) {
         $result->error(sprintf(_t("Checkout.IDFIELDNOTFOUND", "Required field not found: %s"), $idfield));
         throw new ValidationException($result);
     }
     if (!isset($data['Password']) || empty($data['Password'])) {
         $result->error(_t("Checkout.PASSWORDREQUIRED", "A password is required"));
         throw new ValidationException($result);
     }
     $idval = $data[$idfield];
     if ($member = ShopMember::get_by_identifier($idval)) {
         // get localized field labels
         $fieldLabels = $member->fieldLabels(false);
         // if a localized value exists, use this for our error-message
         $fieldLabel = isset($fieldLabels[$idfield]) ? $fieldLabels[$idfield] : $idfield;
         $result->error(sprintf(_t("Checkout.MEMBEREXISTS", "A member already exists with the %s %s"), $fieldLabel, $idval));
         throw new ValidationException($result);
     }
     $member = Member::create(Convert::raw2sql($data));
     // 3.2 changed validate to protected which made this fall through the DataExtension and error out
     $validation = $member->hasMethod('doValidate') ? $member->doValidate() : $member->validate();
     if (!$validation->valid()) {
         //TODO need to handle i18n here?
         $result->error($validation->message());
     }
     if (!$result->valid()) {
         throw new ValidationException($result);
     }
     return $member;
 }
示例#20
0
            $data = array();
            $data['password'] = md5($new_password);
            $data['firstname'] = sanitize($_POST['qr_candidate_firstname']);
            $data['lastname'] = sanitize($_POST['qr_candidate_lastname']);
            $data['phone_num'] = sanitize($_POST['qr_candidate_phone']);
            $data['zip'] = '0';
            $data['country'] = sanitize($_POST['qr_candidate_country']);
            $data['forget_password_question'] = 1;
            $data['forget_password_answer'] = 'system generated';
            $data['joined_on'] = $today;
            $data['active'] = 'N';
            $data['invites_available'] = '10';
            $data['checked_profile'] = 'N';
            $data['like_newsletter'] = 'N';
            $data['filter_jobs'] = 'N';
            if (!$new_member->create($data)) {
                ?>
<script type="text/javascript">top.stop_quick_refer_upload('-3');</script><?php 
                exit;
            }
            $activation_id = microtime(true);
            $query = "INSERT INTO member_activation_tokens SET \n                      id = '" . $activation_id . "', \n                      member = '" . $candidate_email . "', \n                      joined_on = '" . $today . "'";
            if (!$mysqli->execute($query)) {
                ?>
<script type="text/javascript">top.stop_quick_refer_upload('-4');</script><?php 
                exit;
            }
            // 2. create an upload resume
            $data = array();
            $data['modified_on'] = $today;
            $data['name'] = $_FILES['qr_my_file']['name'];
示例#21
0
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     // Default groups should've been built by Group->requireDefaultRecords() already
     // Find or create ADMIN group
     $adminGroup = Permission::get_groups_by_permission('ADMIN')->First();
     if (!$adminGroup) {
         singleton('Group')->requireDefaultRecords();
         $adminGroup = Permission::get_groups_by_permission('ADMIN')->First();
     }
     // Add a default administrator to the first ADMIN group found (most likely the default
     // group created through Group->requireDefaultRecords()).
     $admins = Permission::get_members_by_permission('ADMIN')->First();
     if (!$admins) {
         // Leave 'Email' and 'Password' are not set to avoid creating
         // persistent logins in the database. See Security::setDefaultAdmin().
         $admin = Member::create();
         $admin->FirstName = _t('Member.DefaultAdminFirstname', 'Default Admin');
         $admin->write();
         $admin->Groups()->add($adminGroup);
     }
 }
示例#22
0
 /**
  * Return an existing member with administrator privileges, or create one of necessary.
  *
  * Will create a default 'Administrators' group if no group is found
  * with an ADMIN permission. Will create a new 'Admin' member with administrative permissions
  * if no existing Member with these permissions is found.
  *
  * Important: Any newly created administrator accounts will NOT have valid
  * login credentials (Email/Password properties), which means they can't be used for login
  * purposes outside of any default credentials set through {@link Security::setDefaultAdmin()}.
  *
  * @return Member
  */
 public static function findAnAdministrator()
 {
     // coupling to subsites module
     $origSubsite = null;
     if (is_callable('Subsite::changeSubsite')) {
         $origSubsite = Subsite::currentSubsiteID();
         Subsite::changeSubsite(0);
     }
     $member = null;
     // find a group with ADMIN permission
     $adminGroup = Permission::get_groups_by_permission('ADMIN')->First();
     if (is_callable('Subsite::changeSubsite')) {
         Subsite::changeSubsite($origSubsite);
     }
     if ($adminGroup) {
         $member = $adminGroup->Members()->First();
     }
     if (!$adminGroup) {
         singleton('Group')->requireDefaultRecords();
         $adminGroup = Permission::get_groups_by_permission('ADMIN')->First();
     }
     if (!$member) {
         singleton('Member')->requireDefaultRecords();
         $member = Permission::get_members_by_permission('ADMIN')->First();
     }
     if (!$member) {
         $member = Member::default_admin();
     }
     if (!$member) {
         // Failover to a blank admin
         $member = Member::create();
         $member->FirstName = _t('Member.DefaultAdminFirstname', 'Default Admin');
         $member->write();
         // Add member to group instead of adding group to member
         // This bypasses the privilege escallation code in Member_GroupSet
         $adminGroup->DirectMembers()->add($member);
     }
     return $member;
 }
示例#23
0
     $joined_on = today();
     $data = array();
     $data['password'] = md5(generate_random_string_of(6));
     $data['phone_num'] = '0';
     $data['firstname'] = $_POST['linkedin_firstname'];
     $data['lastname'] = $_POST['linkedin_lastname'];
     $data['linkedin_id'] = $linkedin_id;
     $data['joined_on'] = $joined_on;
     $data['updated_on'] = $joined_on;
     $data['active'] = 'Y';
     $data['checked_profile'] = 'Y';
     if (is_null($data['firstname']) || empty($data['firstname']) || is_null($data['lastname']) || empty($data['lastname'])) {
         $data['firstname'] = 'Unknown';
         $data['lastname'] = 'Unknown';
     }
     if ($member->create($data) === false) {
         $_SESSION['yel']['member']['hash'] = "";
         $response['errors'] = array('error' => 'create_error');
         echo $xml_dom->get_xml_from_array($response);
         exit;
     }
 } else {
     // reverse check by looking for linkedin_id from id.
     // if it is empty, then update.
     // if it is not a match with the supplied linkedin_id, then error out
     $stored_linkedin_id = $member->getLinkedInId();
     if ($stored_linkedin_id !== false && is_null($stored_linkedin_id)) {
         // update
         $data = array();
         $data['linkedin_id'] = $linkedin_id;
         $member->setAdmin(true);
示例#24
0
文件: Member.php 项目: 8secs/cocina
 /**
  * Get the default admin record if it exists, or creates it otherwise if enabled
  *
  * @return Member
  */
 public static function default_admin()
 {
     // Check if set
     if (!Security::has_default_admin()) {
         return null;
     }
     // Find or create ADMIN group
     singleton('Group')->requireDefaultRecords();
     $adminGroup = Permission::get_groups_by_permission('ADMIN')->First();
     // Find member
     $admin = Member::get()->filter('Email', Security::default_admin_username())->first();
     if (!$admin) {
         // 'Password' is not set to avoid creating
         // persistent logins in the database. See Security::setDefaultAdmin().
         // Set 'Email' to identify this as the default admin
         $admin = Member::create();
         $admin->FirstName = _t('Member.DefaultAdminFirstname', 'Default Admin');
         $admin->Email = Security::default_admin_username();
         $admin->write();
     }
     // Ensure this user is in the admin group
     if (!$admin->inGroup($adminGroup)) {
         $admin->Groups()->add($adminGroup);
     }
     return $admin;
 }
 public static function _doAddMember()
 {
     $user = User::find(intval($_SESSION['userid']));
     $member = Member::find(intval($_SESSION['memberid']));
     $division = Division::findById($member->game_id);
     $platoon_id = $user->role >= 3 || User::isDev() ? $_POST['platoon_id'] : $member->platoon_id;
     $squad_id = $user->role >= 2 || User::isDev() ? $_POST['squad_id'] : Squad::mySquadId($member->id) ?: 0;
     $recruiter = $member->member_id;
     $position_id = 6;
     // provide params for brand new members
     $params = array('member_id' => $_POST['member_id'], 'forum_name' => trim($_POST['forum_name']), 'recruiter' => $recruiter, 'game_id' => $_POST['game_id'], 'status_id' => 999, 'join_date' => date("Y-m-d H:i:s"), 'last_forum_login' => date("Y-m-d H:i:s"), 'last_activity' => date("Y-m-d H:i:s"), 'last_forum_post' => date("Y-m-d H:i:s"), 'last_promotion' => date("Y-m-d H:i:s"), 'rank_id' => 1, 'platoon_id' => $platoon_id, 'squad_id' => $squad_id, 'position_id' => $position_id);
     if (Member::exists($_POST['member_id'])) {
         // update existing record
         $existing_member_id = Member::findId($_POST['member_id']);
         $params = array_merge($params, array('id' => $existing_member_id));
         $affected_rows = Member::modify($params);
         if ($affected_rows > 0) {
             UserAction::create(array('type_id' => 10, 'date' => date("Y-m-d H:i:s"), 'user_id' => $member->member_id, 'target_id' => $params['member_id']));
             $data = array('success' => true, 'message' => "Existing member successfully updated!");
         } else {
             $data = array('success' => false, 'message' => "Existing member could not be updated.");
         }
     } else {
         // member doesn't exist
         $insert_id = Member::create($params);
         if ($insert_id != 0) {
             UserAction::create(array('type_id' => 1, 'date' => date("Y-m-d H:i:s"), 'user_id' => $member->member_id, 'target_id' => $params['member_id']));
             $data = array('success' => true, 'message' => "Member successfully added!");
         } else {
             $data = array('success' => false, 'message' => "Member could not be added.");
         }
     }
     if ($insert_id != 0) {
         if (isset($_POST['played_games'])) {
             $games = $_POST['played_games'];
             foreach ($games as $game) {
                 $memberGame = new stdClass();
                 $memberGame->member_id = $insert_id;
                 $memberGame->game_id = $game;
                 MemberGame::add($memberGame);
             }
         }
         if (isset($_POST['ingame_name'])) {
             $ingame_name = trim($_POST['ingame_name']);
             $handle = new stdClass();
             $handle->member_id = $insert_id;
             $handle->handle_type = $division->primary_handle;
             $handle->handle_value = $ingame_name;
             $handle->handle_account_id = '0';
             $handle->invalid = '0';
             $handle->invalid_date = '0000-00-00';
             MemberHandle::add($handle);
         }
     }
     echo json_encode($data);
 }
 /**
  * set up a group with permissions, roles, etc...
  * also @see EcommerceRole::providePermissions
  * also note that this class implements PermissionProvider
  * @param String $code code for the group - will always be converted to lowercase
  * @param String $name title for the group
  * @param Group | String $parentGroup group object that is the parent of the group. You can also provide a string (name / title of group)
  * @param String $permissionCode Permission Code for the group (e.g. CMS_DO_THIS_OR_THAT)
  * @param String $roleTitle Role Title - e.g. Store Manager
  * @param Array $permissionArray Permission Array - list of permission codes applied to the group
  * @param Member | String $member Default Member added to the group (e.g. sales@mysite.co.nz). You can also provide an email address
  *
  */
 public function CreateGroup($code, $name, $parentGroup = null, $permissionCode = "", $roleTitle = "", $permissionArray = array(), $member = null)
 {
     //changing to lower case seems to be very important
     //unidentified bug so far
     $code = strtolower($code);
     if (!$code) {
         user_error("Can't create a group without a {$code} ({$name})");
     }
     if (!$name) {
         user_error("Can't create a group without a {$name} ({$code})");
     }
     $group = Group::get()->filter(array("Code" => $code))->first();
     $groupCount = Group::get()->filter(array("Code" => $code))->count();
     $groupStyle = "updated";
     if ($groupCount > 1) {
         user_error("There is more than one group with the {$name} ({$code}) Code");
     }
     if (!$group) {
         $group = Group::create();
         $group->Code = $code;
         $groupStyle = "created";
     }
     $group->Locked = 1;
     $group->Title = $name;
     $parentGroupStyle = "updated";
     if ($parentGroup) {
         DB::alteration_message("adding parent group");
         if (is_string($parentGroup)) {
             $parentGroupName = $parentGroup;
             $parentGroup = Group::get()->filter(array("Title" => $parentGroupName))->first();
             if (!$parentGroup) {
                 $parentGroup = Group::create();
                 $parentGroupStyle = "created";
                 $parentGroup->Title = $parentGroupName;
                 $parentGroup->write();
                 DB::alteration_message("{$parentGroupStyle} {$parentGroupName}", $parentGroupStyle);
             }
         }
         if ($parentGroup) {
             $group->ParentID = $parentGroup->ID;
         }
     }
     $group->write();
     DB::alteration_message("{$groupStyle} {$name} ({$code}) group", $groupStyle);
     $doubleGroups = Group::get()->filter(array("Code" => $code))->exclude(array("ID" => $group->ID));
     if ($doubleGroups->count()) {
         DB::alteration_message($doubleGroups->count() . " groups with the same name", "deleted");
         $realMembers = $group->Members();
         foreach ($doubleGroups as $doubleGroup) {
             $fakeMembers = $doubleGroup->Members();
             foreach ($fakeMembers as $fakeMember) {
                 DB::alteration_message("adding customers: " . $fakeMember->Email, "created");
                 $realMembers->add($fakeMember);
             }
             DB::alteration_message("deleting double group ", "deleted");
             $doubleGroup->delete();
         }
     }
     if ($permissionCode) {
         $permissionCodeCount = DB::query("SELECT * FROM \"Permission\" WHERE \"GroupID\" = '" . $group->ID . "' AND \"Code\" LIKE '" . $permissionCode . "'")->numRecords();
         if ($permissionCodeCount == 0) {
             DB::alteration_message("granting " . $name . " permission code {$permissionCode} ", "created");
             Permission::grant($group->ID, $permissionCode);
         } else {
             DB::alteration_message($name . " permission code {$permissionCode} already granted");
         }
     }
     //we unset it here to avoid confusion with the
     //other codes we use later on
     unset($permissionCode);
     if ($roleTitle) {
         $permissionRole = PermissionRole::get()->Filter(array("Title" => $roleTitle))->First();
         $permissionRoleCount = PermissionRole::get()->Filter(array("Title" => $roleTitle))->Count();
         if ($permissionRoleCount > 1) {
             db::alteration_message("There is more than one Permission Role with title {$roleTitle} ({$permissionCodeObjectCount})", "deleted");
             $permissionRolesToDelete = PermissionRole::get()->Filter(array("Title" => $roleTitle))->Exclude(array("ID" => $permissionRole->ID));
             foreach ($permissionRolesToDelete as $permissionRoleToDelete) {
                 db::alternation_message("DELETING double permission role {$roleTitle}", "deleted");
                 $permissionRoleToDelete->delete();
             }
         }
         if ($permissionRole) {
             //do nothing
             DB::alteration_message("{$roleTitle} role in place");
         } else {
             DB::alteration_message("adding {$roleTitle} role", "created");
             $permissionRole = PermissionRole::create();
             $permissionRole->Title = $roleTitle;
             $permissionRole->OnlyAdminCanApply = true;
             $permissionRole->write();
         }
         if ($permissionRole) {
             if (is_array($permissionArray) && count($permissionArray)) {
                 DB::alteration_message("working with " . implode(", ", $permissionArray));
                 foreach ($permissionArray as $permissionRoleCode) {
                     $permissionRoleCodeObject = PermissionRoleCode::get()->Filter(array("Code" => $permissionRoleCode, "RoleID" => $permissionRole->ID))->First();
                     $permissionRoleCodeObjectCount = PermissionRoleCode::get()->Filter(array("Code" => $permissionRoleCode, "RoleID" => $permissionRole->ID))->Count();
                     if ($permissionRoleCodeObjectCount > 1) {
                         $permissionRoleCodeObjectsToDelete = PermissionRoleCode::get()->Filter(array("Code" => $permissionRoleCode, "RoleID" => $permissionRole->ID))->Exclude(array("ID" => $permissionRoleCodeObject->ID));
                         foreach ($permissionRoleCodeObjectsToDelete as $permissionRoleCodeObjectToDelete) {
                             db::alteration_message("DELETING double permission code {$permissionRoleCode} for " . $permissionRole->Title, "deleted");
                             $permissionRoleCodeObjectToDelete->delete();
                         }
                         db::alteration_message("There is more than one Permission Role Code in " . $permissionRole->Title . " with Code = {$permissionRoleCode} ({$permissionRoleCodeObjectCount})", "deleted");
                     }
                     if ($permissionRoleCodeObject) {
                         //do nothing
                     } else {
                         $permissionRoleCodeObject = PermissionRoleCode::create();
                         $permissionRoleCodeObject->Code = $permissionRoleCode;
                         $permissionRoleCodeObject->RoleID = $permissionRole->ID;
                     }
                     DB::alteration_message("adding " . $permissionRoleCodeObject->Code . " to " . $permissionRole->Title);
                     $permissionRoleCodeObject->write();
                 }
             }
             if ($group && $permissionRole) {
                 if (DB::query("SELECT COUNT(*) FROM Group_Roles WHERE GroupID = " . $group->ID . " AND PermissionRoleID = " . $permissionRole->ID)->value() == 0) {
                     db::alteration_message("ADDING " . $permissionRole->Title . " permission role  to " . $group->Title . " group", "created");
                     $existingGroups = $permissionRole->Groups();
                     $existingGroups->add($group);
                 } else {
                     db::alteration_message("CHECKED " . $permissionRole->Title . " permission role  to " . $group->Title . " group");
                 }
             } else {
                 db::alteration_message("ERROR: missing group or permissionRole", "deleted");
             }
         }
     }
     if ($member) {
         if (is_string($member)) {
             $email = $member;
             $member = Member::get()->filter(array("Email" => $email))->first();
             if (!$member) {
                 DB::alteration_message("Creating default user", "created");
                 $member = Member::create();
                 $member->FirstName = $code;
                 $member->Surname = $name;
                 $member->Email = $email;
                 $member->write();
             }
         }
         if ($member) {
             DB::alteration_message(" adding member " . $member->Email . " to group " . $group->Title, "created");
             $member->Groups()->add($group);
         }
     } else {
         DB::alteration_message("No need to add user");
     }
 }
示例#27
0
require "../inc/common_cli.php";

require "../inc/functions_test.php";


// to avoid conflicts with existing usernames
$date = dechex(time());

$ngroup = new_ngroup("Test ballots group", 500, 25);

// create main member
$login = new Member;
$login->invite = Login::generate_token(24);
$login->eligible = true;
$login->verified = true;
$login->create();
$login->username = "******".$date."login";
$login->password = $password;
$login->mail = ERROR_MAIL;
$login->update(['username', 'password', 'eligible', 'mail'], 'activated=now()');


// go through all cases
$case = 0;
do {
	$stopcase = 0;
	do {
		$case++;
		$stopcase++;
	} while ( ! $return = create_case($case, $stopcase) );
} while ( $return !== "end" );
示例#28
0
</p><p style="font-weight: bold;">Find a member... </p><p><?php 
$criteria = array('columns' => 'members.email_addr, 
                  CONCAT(members.firstname, \' \', members.lastname) AS name, 
                  countries.country, currencies.symbol', 'match' => 'email_addr = \'pamalite@gmail.com\'', 'joins' => 'countries ON countries.country_code = members.country, 
                currencies ON currencies.country_code = countries.country_code');
$members = Member::find($criteria);
print_array($members);
?>
</p><p style="font-weight: bold;">Create a new member... </p><p><?php 
$member = new Member('*****@*****.**');
$data = array();
$data['password'] = md5('bibi');
$data['forget_password_question'] = 1;
$data['forget_password_answer'] = 'bibi answer';
$data['phone_num'] = '222 2234 4566';
$data['firstname'] = 'Bibi';
$data['lastname'] = 'Choon';
$data['zip'] = '0A33Z8';
$data['country'] = 'CA';
if ($member->create($data)) {
    $criteria = array('columns' => 'members.email_addr, 
                      CONCAT(members.firstname, \' \', members.lastname) AS name, 
                      countries.country, currencies.symbol', 'match' => 'email_addr = \'bibi@bibi.com\'', 'joins' => 'countries ON countries.country_code = members.country, 
                    currencies ON currencies.country_code = countries.country_code');
    print_array(Member::find($criteria));
} else {
    echo "exit";
    exit;
}
?>
</p>
示例#29
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return Member::create(['name' => $data['name'], 'email1' => $data['email'], 'password' => bcrypt($data['password'])]);
 }
示例#30
0
 public static function search($values = array())
 {
     $result1 = DB::getInstance()->search("member", $values);
     if (count($result1) != 0) {
         $result2 = DB::getInstance()->search("member_role", array("member_id" => $result1[0]["member_id"]));
         $mem_type = array();
         for ($x = 0; $x < count($result2); $x++) {
             $mem_type[$x] = $result2[$x]["role"];
         }
         $member_data = array("id" => $result1[0]["member_id"], "nic_no" => $result1[0]["member_nic"], "initials" => $result1[0]["member_initials"], "surname" => $result1[0]["member_surname"], "email" => $result1[0]["member_email"], "password" => $result1[0]["member_password"], "type" => $mem_type, "validity" => $result1[0]["member_validity"], "remarks" => $result1[0]["member_remarks"]);
         $new_member = new Member();
         $new_member->create($member_data);
         return $new_member;
     } else {
         return null;
     }
 }