<?php

namespace auth;

class appmaster
{
    /**
     * 注册应用
     * @param $appid
     * @param $apppwd
     * @param $url
     * @param $type
     * @param $scope
     * @param $userid
     * @param $name
     * @param $home
     * @param $present
     * @return array|false|mixed|string
     */
    public function reg($appid,$apppwd,$url,$type=null,$scope=null,$userid,$name,$home,$present){
        global $authsql;
        return $authsql->insert('oauth_clients',[
            'client_id'=>$appid,
            'client_secret'=>$apppwd,
            'redirect_uri'=>$url,
            'grant_types'=>$type,
            'scope'=>$scope,
            'user_id'=>$userid,
            'name'=>$name,
            'home'=>$home,
            'present'=>$present,
        ]);
    }

    /**
     * 删除应用
     * @param $id
     * @return false|int
     */
    public function del($id){
        global $authsql;
        return $authsql->delete('oauth_clients',[
            'id'=>$id
        ]);
    }

    public function edit($appid,$name,$home,$domain,$present){
        global $authsql;
        return $authsql->update('oauth_clients',[
            'name'=>$name,
            'home'=>$home,
            "redirect_uri"=>$domain,
            "present"=>$present
        ],[
            "client_id"=>$appid
            ]
        );
    }
}