示例#1
0
 /**
     User logs in
 */
 public static function login($l, $p)
 {
     $user = R::findOne("user", "(@email=:l) and pwhash=:p", array('l' => $l, 'p' => sha1($p)));
     if (!$user) {
         RedView::end('error', 'User name and password don\'t match.');
     }
     $_SESSION['user'] = $user->export();
     RedView::end('message', 'Logged in.');
 }
示例#2
0
 /**
     simple access control
 */
 protected static function access($roles)
 {
     $user = self::getUser() or RedView::end('error', 'Log in first.');
     $rs = explode(',', trim($roles, ','));
     $us = explode(',', trim($user->roles, ','));
     foreach ($rs as $r) {
         foreach ($us as $u) {
             if ($r == $u) {
                 return $user;
             }
         }
     }
     RedView::end('error', 'You don\'t have permission to do that.');
 }
示例#3
0
 /**
     Update a mailing list
 */
 public static function updateList()
 {
     self::access('admin');
     Model_List::updateBean($_REQUEST);
     RedView::end('message', 'List updated.');
 }
示例#4
0
 public function edit()
 {
     $this->beanType = RedView::args(1);
     $this->id = RedView::args(2);
     $model = "Model_{$this->beanType}";
     if ($this->id) {
         $_REQUEST['id'] = $this->id;
         $model::updateBean($_REQUEST);
     } else {
         $model::createBean($_REQUEST);
     }
     $verb = $this->id ? "updated" : "created";
     RedView::end('message', "{$this->name} {$verb}.");
 }
示例#5
0
 public function onConstraintFail($eventName, $sender, $message = null)
 {
     die($message);
     RedView::end('error', $message);
 }
示例#6
0
 /**
     User registers
 */
 public static function register()
 {
     $bean = Model_User::createBean($_REQUEST);
     $_SESSION['user'] = $bean->export();
     RedView::end('message', 'Your account has been created.');
 }