aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CamilStaps/BotleaguesApi/User.php3
-rw-r--r--src/controllers/UserController.php29
-rw-r--r--src/migrations/2015_02_23_184402_botleaguesapi-create_users.php1
3 files changed, 29 insertions, 4 deletions
diff --git a/src/CamilStaps/BotleaguesApi/User.php b/src/CamilStaps/BotleaguesApi/User.php
index f9db0ee..849ae83 100644
--- a/src/CamilStaps/BotleaguesApi/User.php
+++ b/src/CamilStaps/BotleaguesApi/User.php
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Model;
class User extends Model {
protected $table = 'users';
- protected $hidden = array('password', 'remember_token', 'api_key');
+ protected $hidden = ['password', 'remember_token', 'api_key'];
+ protected $fillable = ['email', 'password'];
} \ No newline at end of file
diff --git a/src/controllers/UserController.php b/src/controllers/UserController.php
index 39c2be6..33e945d 100644
--- a/src/controllers/UserController.php
+++ b/src/controllers/UserController.php
@@ -1,18 +1,43 @@
<?php
namespace CamilStaps\BotleaguesApi;
+use Illuminate\Support\Facades\Hash;
+use Illuminate\Support\Facades\Input;
+use Illuminate\Support\Facades\Redirect;
+
class UserController extends BaseController {
+ protected $user;
+
+ public function __construct(User $user) {
+ $this->user = $user;
+ }
+
public function index() {
- return User::all();
+ return $this->user->all();
}
public function show($id) {
- return User::findOrFail($id);
+ return $this->user->findOrFail($id);
}
public function edit($id) {
return $this->response->noContent();
}
+ public function store() {
+ try {
+ $this->user->email = Input::get('email');
+ $this->user->password = Hash::make(Input::get('password'));
+
+ if ($this->user->save()) {
+ return $this->response->created();
+ } else {
+ throw new Dingo\Api\Exception\StoreResourceFailedException;
+ }
+ } catch (Exception $e) {
+ throw new Dingo\Api\Exception\StoreResourceFailedException;
+ }
+ }
+
} \ No newline at end of file
diff --git a/src/migrations/2015_02_23_184402_botleaguesapi-create_users.php b/src/migrations/2015_02_23_184402_botleaguesapi-create_users.php
index 10d6660..b768180 100644
--- a/src/migrations/2015_02_23_184402_botleaguesapi-create_users.php
+++ b/src/migrations/2015_02_23_184402_botleaguesapi-create_users.php
@@ -18,7 +18,6 @@ class BotleaguesapiCreateUsers extends Migration {
$table->string('email', 127)->unique();
$table->string('password', 60);
$table->rememberToken();
- $table->string('api_key', 255);
$table->timestamps();
});
}