コード例 #1
0
ファイル: User.php プロジェクト: zetbaitsu/DiskonMania-API
 public static function register($username, $name, $password)
 {
     $user = new User();
     $user->username = $username;
     $user->name = $name;
     $user->password = md5($password);
     $user->token = md5(uniqid($username, true));
     if (Capsule::table(User::TABLE_NAME)->where('username', '=', $username)->first() == null) {
         $user->save();
         return User::login($username, $password);
     } else {
         throw new \Exception($username . " has ben taken.");
     }
 }
コード例 #2
0
ファイル: index.php プロジェクト: zetbaitsu/DiskonMania-API
use Zelory\DiskonMania\Util\Scraper;
require 'vendor/autoload.php';
require_once 'src/zelory/diskonmania/DB.php';
$container = new Container();
$container['foundHandler'] = function () {
    return new RequestResponseArgs();
};
$app = new App($container);
$app->get('/', function (Request $request, Response $response) {
    $response->getBody()->write('<script type="text/javascript">url = window.location.href + "doc"; window.location = url;</script>');
    return $response->withStatus(200)->withHeader('Content-Type', 'text/html');
});
$app->post('/login', function (Request $request, Response $response) {
    try {
        $params = $request->getQueryParams();
        $user = User::login($params['username'], $params['password']);
        if ($user == null) {
            throw new Exception("Invalid username or password!");
        }
        return ResultWrapper::getResult($user, $response);
    } catch (Exception $e) {
        return ResultWrapper::getError($e->getMessage(), $response);
    }
});
$app->post('/register', function (Request $request, Response $response) {
    try {
        $params = $request->getQueryParams();
        $user = User::register($params['username'], $params['name'], $params['password']);
        if ($user == null) {
            throw new Exception("Invalid username or password!");
        }