Example #1
0
 public static function find($id)
 {
     $db = Database::getInstance();
     $pstmt = $db->prepare("SELECT * FROM user WHERE email = :x");
     $pstmt->execute(array(':x' => $id));
     $result = $pstmt->fetch(PDO::FETCH_OBJ);
     $p = new User();
     if ($result) {
         $p->setID($result->id);
         $p->setEmail($result->email);
         $p->setPassword($result->password);
         $p->setIsActive($result->isActive);
         $p->setUsername($result->username);
         $p->setImage($result->image);
         $p->setDescription($result->description);
         $p->setFerraille($result->ferraille);
         $p->setPrestige($result->prestige);
         $pstmt->closeCursor();
         $db = Database::close();
         return $p;
     }
     $pstmt->closeCursor();
     $db = Database::close();
     return null;
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $user = new User();
     $user->setUsername($arguments['username']);
     $user->setPassword($arguments['password']);
     $user->setIsActive(true);
     $user->save();
     $this->log('User ' . $arguments['username'] . ' created');
 }
Example #3
0
File: schema.php Project: cmsx/auth
 protected function createUser($active = true)
 {
     $u = new User();
     $u->setIsActive($active);
     $u->setRole(User::ROLE_ADMIN);
     $u->setLogin('test');
     $u->setName('Test User');
     $u->setPassword('qwerty');
     $u->save();
     return $u;
 }
 public function executeNewuser(sfWebRequest $request)
 {
     $this->form = new UserForm();
     // check if the data is coming from POST method
     if ($request->isMethod('post')) {
         // bind the form
         $this->form->bind($request->getParameter($this->form->getName()));
         $captcha = new reCaptcha();
         $responsecaptcha = $captcha->recaptcha_check_answer($_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
         //check capcha
         if (!$responsecaptcha->is_valid) {
             $this->getUser()->setFlash('message', 'Invalid Sequrity Code,Please enter again');
         } else {
             $formData = $this->form->getValues();
             $checkUsernameAndEmail = Doctrine::getTable('User')->func_checkUsernameAndEmail($formData['email_address'], $formData['username']);
             if (count($checkUsernameAndEmail)) {
                 $this->getUser()->setFlash('message', 'UserName or Email is already taken');
             } else {
                 $user = new User();
                 $user->setUsername($formData['username']);
                 $getSalt = Doctrine::getTable('User')->func_generateSalt();
                 $getPassword = Doctrine::getTable('User')->func_generatePassword($getSalt, $formData['pass']);
                 $user->setSalt($getSalt);
                 $user->setPass($getPassword);
                 $user->setIsActive(0);
                 $user->setFirstName($formData['first_name']);
                 $user->setLastName($formData['last_name']);
                 $user->setEmailAddress($formData['email_address']);
                 $user->save();
                 Doctrine::getTable('User')->func_sendVerificationEmail($formData['first_name'], $formData['email_address'], $getSalt);
                 $this->getUser()->setFlash('message', 'Thanks for registration. Account activation link has been sent into your email address.');
                 $this->redirect('@login');
             }
             // if the username and email does not exist
         }
     }
     // check if the method is POST
 }
Example #5
0
function login_ldap($username, $password)
{
    // ldap connecting: must be a valid LDAP server!
    try {
        $ds = ldap_connect("ds.uni-sofia.bg");
    } catch (Exception $e) {
        $error = new Error("User: {$username} failed login:"******"uid={$username},ou=People,dc=uni-sofia,dc=bg";
            $userbind = ldap_bind($ds, $user_dn, $password);
            // verify binding
            if ($userbind) {
                global $ldapRdn;
                global $ldapPass;
                // set ldap bind variables
                $ldaprdn = $ldapRdn;
                $ldappass = $ldapPass;
                // binding to ldap server
                $ldapbind = ldap_bind($ds, $ldaprdn, $ldappass);
                // verify binding
                if ($ldapbind) {
                    // data array
                    $array = array("displayname", "mail", "title", "suscientifictitle", "suscientificdegree", "suFaculty", "suDepartment", "suStudentFaculty", "ou", "objectclass");
                    //$array = array("displayname", "mail", "title");
                    $sr = ldap_search($ds, "ou=People,dc=uni-sofia,dc=bg", "(uid={$username})", $array, 0, 0, 0);
                    $pass = md5($password);
                    $email = "";
                    $givenname = "";
                    $title = "";
                    $staff_groups = "";
                    $student_groups = "";
                    $staff_groups_id = array();
                    $student_groups_id = array();
                    $student_groups_array = array();
                    $staff_groups_array = array();
                    $info = ldap_get_entries($ds, $sr);
                    for ($i = 0; $i < count($info); $i++) {
                        if (isset($info[$i]['mail'])) {
                            $email = $info[$i]['mail'][0];
                        }
                        if (isset($info[$i]['displayname'])) {
                            $givenname = $info[$i]['displayname'][0];
                        }
                        if (isset($info[$i]['title'])) {
                            $title .= $info[$i]['title'][0];
                        }
                        if (isset($info[$i]['suscientifictitle'])) {
                            $title .= " " . $info[$i]['suscientifictitle'][0];
                        }
                        if (isset($info[$i]['suscientificdegree'])) {
                            $title .= " " . $info[$i]['suscientificdegree'][0];
                        }
                        if (isset($info[$i]['objectclass'])) {
                            if (in_array("suStudentPerson", $info[$i]['objectclass']) && !in_array("suFacultyPerson", $info[$i]['objectclass'])) {
                                if (isset($info[$i]['sustudentfaculty'])) {
                                    foreach ($info[$i]['sustudentfaculty'] as $student_group) {
                                        if (!is_int($student_group)) {
                                            array_push($student_groups_array, $student_group);
                                        }
                                    }
                                } elseif (isset($info[$i]['sufaculty'])) {
                                    foreach ($info[$i]['sufaculty'] as $student_group) {
                                        if (!is_int($student_group)) {
                                            array_push($student_groups_array, $student_group);
                                        }
                                    }
                                }
                            }
                            if (in_array("suStaffPerson", $info[$i]['objectclass']) || in_array("suFacultyPerson", $info[$i]['objectclass'])) {
                                if (isset($info[$i]['sufaculty'])) {
                                    foreach ($info[$i]['sufaculty'] as $staff_group) {
                                        if (!is_int($staff_group) && !in_array($staff_group, $student_groups_array)) {
                                            array_push($staff_groups_array, $staff_group);
                                        }
                                    }
                                }
                                if (isset($info[$i]['sudepartment'])) {
                                    foreach ($info[$i]['sudepartment'] as $staff_group) {
                                        if (!is_int($staff_group)) {
                                            array_push($staff_groups_array, $staff_group);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // get the ids of the staff groups
                    foreach ($staff_groups_array as $staff_group_name) {
                        $staff_group_ids = get_group_by_name($staff_group_name);
                        if (!empty($staff_group_ids)) {
                            foreach ($staff_group_ids as $group_id) {
                                $group = new Group();
                                $group->get_from_db($group_id);
                                if ($group->getLocal() == "0" && $group->getStudent() == "0" && $group->getStaff() == "1") {
                                    array_push($staff_groups_id, $group_id);
                                }
                            }
                        }
                    }
                    // get the ids of the student groups
                    foreach ($student_groups_array as $student_group_name) {
                        $student_group_ids = get_group_by_name($student_group_name);
                        if (!empty($student_group_ids)) {
                            foreach ($student_group_ids as $group_id) {
                                $group = new Group();
                                $group->get_from_db($group_id);
                                if ($group->getLocal() == "0" && $group->getStudent() == "1" && $group->getStaff() == "0") {
                                    array_push($student_groups_id, $group_id);
                                }
                            }
                        }
                    }
                    // set common properties
                    $staff_groups .= serialize($staff_groups_id);
                    $student_groups .= serialize($student_groups_id);
                    $user = new User();
                    $user->setUsername($username);
                    $user->setPassword($pass);
                    $user->setLocal(0);
                    $user_exists = get_user_by_username($username);
                    $time_now = date("Y-m-d H:i:s");
                    if (!empty($user_exists)) {
                        $user->get_from_db($user_exists[0]);
                        $user->setGivenname($givenname);
                        $user->setTitle($title);
                        $user->setStaffGroups($staff_groups);
                        $user->setStudentGroups($student_groups);
                        $user->setId($user_exists[0]);
                        $user->setId($pass);
                        $user->setLastEditedOn($time_now);
                        $user->update_in_db();
                        $info = new Info("User: id " . $user->getId() . " update in db");
                        $info->writeLog();
                    } else {
                        $user->setEmail($email);
                        $user->setCanVote(1);
                        $user->setCanAsk(0);
                        $user->setAdmin(0);
                        $user->setGivenname($givenname);
                        $user->setTitle($title);
                        $user->setStaffGroups($staff_groups);
                        $user->setStudentGroups($student_groups);
                        $user->setLocalGroups(serialize(array()));
                        $user->setIsActive(1);
                        $user->setCreatedOn($time_now);
                        $user->setLastEditedOn($time_now);
                        $user->store_in_db();
                        $info = new Info("User: {$username} added in db");
                        $info->writeLog();
                    }
                    ldap_close($ds);
                }
            }
        } catch (Exception $e) {
            $error = new Error("User: {$username} failed login:"******"LDAP server unavailable");
        $error->writeLog();
    }
}
<?php

require_once "../DataStoreMgr/UserDataStore.php";
require_once "../BusinessObjects/User.php";
$user = new User();
$user->setUserName("baljeet");
$user->setEmailId("*****@*****.**");
$user->setIsActive(true);
$user->setPassword("aa");
$UDS = new UserDataStore();
$UDS->Save($user);
Example #7
0
 public function populateObject($rsItem)
 {
     $seq_ = $rsItem["seq"];
     $fullname = $rsItem["fullname"];
     $username_ = $rsItem["username"];
     $password_ = $rsItem["password"];
     $emailId_ = $rsItem["emailid"];
     $dateOfRegistration_ = $rsItem["dateofregistration"];
     $isActive_ = $rsItem["isactive"];
     $isManager_ = $rsItem["ismanager"];
     $locationSeq_ = $rsItem["locationseq"];
     $folderSeq_ = $rsItem["folderseq"];
     $locationName_ = $rsItem["locationName"];
     $mobile_ = $rsItem["mobile"];
     $user = new User();
     $user->setSeq($seq_);
     $user->setFullName($fullname);
     $user->setUserName($username_);
     $user->setPassword($password_);
     $user->setDecodedPassword(SecurityUtil::Decode($password_));
     $user->setEmailId($emailId_);
     $user->setDateOfRegistration($dateOfRegistration_);
     $user->setConfirmPassword($password_);
     $user->setIsActive($isActive_);
     $user->setIsManager($isManager_);
     $user->setLocationSeq($locationSeq_);
     $user->setFolderSeq($folderSeq_);
     $user->setLocationName($locationName_);
     $user->setMobile($mobile_);
     $otherLocationSeqs = $this->getLocationUsersLocationSeqs($user->getSeq(), $locationSeq_);
     $user->setOtherLocationSeqs($otherLocationSeqs);
     return $user;
 }