示例#1
0
    disable_cache($app);
    _checkInviteTokenAndExec($token, function ($user) use($app) {
        $page = array('email' => $user->getEmail(), 'auth_salt' => DW_AUTH_SALT);
        add_header_vars($page, 'about', 'account/invite.css');
        $app->render('account/invite.twig', $page);
    });
});
/*
 * store new password, clear invitation token and login
 */
$app->post('/account/invite/:token', function ($token) use($app) {
    _checkInviteTokenAndExec($token, function ($user) use($app) {
        $data = json_decode($app->request()->getBody());
        $user->setPwd($data->pwd);
        $user->setActivateToken('');
        $user->save();
        // notify plugins about the newly activated user
        DatawrapperHooks::execute(DatawrapperHooks::USER_ACTIVATED, $user);
        DatawrapperSession::login($user);
        print json_encode(array('result' => 'ok'));
    });
});
function _checkInviteTokenAndExec($token, $func)
{
    if (!empty($token)) {
        $user = UserQuery::create()->findOneByActivateToken($token);
        if ($user && $user->getRole() != 'pending') {
            $func($user);
        } else {
            // this is not a valid token!
            $page['alert'] = array('type' => 'error', 'message' => __('The invitation token is invalid.'));
            global $app;
 */
$app->get('/account/invite/:token', function ($token) use($app) {
    _checkInviteTokenAndExec($token, function ($user) use($app) {
        $page = array('email' => $user->getEmail(), 'auth_salt' => DW_AUTH_SALT);
        add_header_vars($page, 'about');
        $app->render('invited.twig', $page);
    });
});
/*
 * store new password, clear invitation token and login
 */
$app->post('/account/invite/:token', function ($token) use($app) {
    _checkInviteTokenAndExec($token, function ($user) use($app) {
        $data = json_decode($app->request()->getBody());
        $user->setPwd($data->pwd);
        $user->setActivateToken('');
        $user->save();
        DatawrapperSession::login($user);
        print json_encode(array('result' => 'ok'));
    });
});
function _checkInviteTokenAndExec($token, $func)
{
    if (!empty($token)) {
        $user = UserQuery::create()->findOneByActivateToken($token);
        if ($user && $user->getRole() != 'pending') {
            $func($user);
        } else {
            // this is not a valid token!
            $page['alert'] = array('type' => 'error', 'message' => __('The invitation token is invalid.'));
            global $app;
            $app->redirect('/');