<?php

class ACMS_POST_Api_Twitter_OAuth_Deauthorize extends ACMS_POST
{
    public function post()
    {
        if (!SUID || !sessionWithSubscription()) {
            return $this->Post;
        }
        if (UID !== SUID && !sessionWithAdministration()) {
            return $this->Post;
        }

        /** @var Acms\Services\SocialLogin\Twitter $twitter */
        $twitter = App::make('twitter-login');
        
        $twitter->saveRequestTokens(null, null);

        $sql = SQL::newUpdate('user');
        $sql->addUpdate('user_twitter_id', '');
        $sql->addWhereOpr('user_id', UID);
        DB::query($sql->get(dsn()), 'exec');
        ACMS_RAM::user(UID, null);

        $this->redirect(acmsLink(array(
            'bid'           => BID,
            'uid'           => UID,
            'admin'         => 'user_edit',
        )));
    }
}
