Exemplo n.º 1
0
 function doApprove()
 {
     if (!($user = lmbActiveRecord::findFirst('lmbCmsUser', array('generated_password = ?', $this->request->get('id'))))) {
         return $this->flashAndRedirect('Вы прошли по неверной ссылке! Убедитесь, что она соответствует ссылке в отправленном вам письме', '/cms_user/forgot_password');
     }
     $user->setHashedPassword($user->getGeneratedPassword());
     $user->setGeneratedPassword('');
     $user->saveSkipValidation();
     $this->flashAndRedirect('Новый пароль активирован', '/cms_user/login');
 }
Exemplo n.º 2
0
 function login($login, $password)
 {
     $criteria = new lmbSQLFieldCriteria('login', $login);
     $user = lmbActiveRecord::findFirst('lmbCmsUser', array('criteria' => $criteria));
     if ($user && $user->isPasswordCorrect($password)) {
         $this->import($user);
         $this->setIsNew(false);
         $this->setLoggedIn(true);
         return true;
     } else {
         $this->setLoggedIn(false);
         return false;
     }
 }
 function testCustomLazyFieldsInFindFirst()
 {
     $object = new TestOneTableObject();
     $object->setAnnotation($annotation = "Annotation");
     $object->setContent($content = "Content");
     $object->save();
     $object2 = lmbActiveRecord::findFirst('TestOneTableObject', array('fields' => array('annotation')));
     $fields = $object2->exportRaw();
     //checking which props were actually loaded
     $this->assertEqual($fields, array('id' => $object->getId(), 'annotation' => $annotation));
     //lazy loading in action
     $this->assertEqual($object2->getAnnotation(), $annotation);
     $this->assertEqual($object2->getContent(), $content);
 }
 function testChildRemovalWithRequiredObjectInParentRelationDefinitionThrowsValidationException()
 {
     $number = $this->creator->initSocialSecurity();
     $person = new PersonForTestWithRequiredSocialSecurity();
     $person->setName('Jim');
     $person->setSocialSecurity($number);
     $number->setPerson($person);
     $person->save();
     try {
         $number->destroy();
         $this->assertTrue(false);
     } catch (lmbValidationException $e) {
         $this->assertTrue(true);
     }
     $number2 = lmbActiveRecord::findFirst('SocialSecurityForTest');
     $this->assertNotNull($number2, 'Removal should not be finished');
     $this->assertEqual($number2->getId(), $number->getId());
 }
 function testFetchFirstWithRelationObjectsUsingAttach_AndThenSave()
 {
     $course1 = $this->creator->createCourse();
     $course2 = $this->creator->createCourse();
     $lecture1 = $this->creator->createLecture($course1);
     $lecture2 = $this->creator->createLecture($course2);
     $lecture3 = $this->creator->createLecture($course2);
     $course2_loaded = lmbActiveRecord::findFirst('CourseForTest', array('criteria' => 'course_for_test.id = ' . $course2->getId(), 'attach' => 'lectures'));
     $course2_loaded->setTitle('Some other title');
     $course2_loaded->save();
     $course2_loaded2 = lmbActiveRecord::findFirst('CourseForTest', array('criteria' => 'course_for_test.id = ' . $course2->getId(), 'attach' => 'lectures'));
     $lectures = $course2_loaded2->getLectures();
     $this->assertEqual(count($lectures), 2);
 }
Exemplo n.º 6
0
 function testFindFirstWithDefaultSortParams()
 {
     $object1 = new TestOneTableObjectWithSortParams();
     $object1->setContent('Content' . mt_rand());
     $object1->save();
     $object2 = new TestOneTableObjectWithSortParams();
     $object2->setContent('Content' . mt_rand());
     $object2->save();
     $found = lmbActiveRecord::findFirst('TestOneTableObjectWithSortParams');
     $this->assertEqual($found->get('id'), $object2->getId());
     //testing convenient alias
     $found = TestOneTableObjectWithSortParams::findFirst();
     $this->assertEqual($found->get('id'), $object2->getId());
 }