예제 #1
0
파일: users.php 프로젝트: jabouzi/contacts
 public function processadd()
 {
     $username = $_POST['username'];
     $password = $_POST['password'];
     $admin = $_POST['admin'];
     $user = new user(array('username' => $username));
     if (!is_null($user->id)) {
         lib::seterror($username . ' is already in use');
         lib::sendto('/users/add');
     }
     $user->username = $username;
     $user->password = lib::makehashedpassword($user, $password);
     $user->admin = $admin;
     $user->save();
     lib::sendto('/users');
 }
예제 #2
0
 public function process()
 {
     $username = $_POST['username'];
     $password = $_POST['password'];
     if (empty($username)) {
         lib::seterror('Please enter a username.');
         lib::sendto('/login');
     }
     if (empty($password)) {
         lib::setitem('username', $username);
         lib::seterror('Please enter a password.');
         lib::sendto('/login');
     }
     $user = new user(array('username' => $username));
     if (auth::authenticate($user, $password)) {
         lib::setitem('user', $user);
         lib::sendto();
     } else {
         lib::setitem('username', $username);
         lib::seterror('Invalid username or password.');
         lib::sendto('/login');
     }
 }
예제 #3
0
 public function processimport()
 {
     if (is_uploaded_file($_FILES['contactsfile']['tmp_name'])) {
         $contents = file_get_contents($_FILES['contactsfile']['tmp_name']);
         unlink($_FILES['contactsfile']['tmp_name']);
         $builder = new importcontactsarraybuilder($contents);
         $imports = $builder->buildarray($_POST['type']);
         $currentuser = lib::getitem('user');
         foreach ($imports as $import) {
             $contact = new contact();
             $adaptor = importadapter::factory($_POST['type']);
             $adaptor->setcontents($import);
             $contact->firstname = $adaptor->firstname;
             $contact->middlename = $adaptor->middlename;
             $contact->lastname = $adaptor->lastname;
             $contact->ownerid = $currentuser->id;
             $contact->save();
             $possiblegroups = array('Business', 'Home');
             foreach ($possiblegroups as $groupname) {
                 $groupfinder = new contactimportgroupinterpreter($import);
                 $group = $groupfinder->getgroup($groupname);
                 if ($group instanceof contactgroup) {
                     $group->contactid = $contact->id;
                     $group->save();
                     $methods = new contactmethodscollection($group);
                     $methods->generateimportmethods($import);
                     $methods->saveall();
                 }
             }
         }
         lib::sendto();
     } else {
         lib::seterror(array('Please upload a file.'));
         lib::sendto('/contacts/import');
     }
 }