public function postRegister() { if (\Input::get('tag') == 'register') { $validator = \Validator::make(\Input::all(), ['name' => 'required', 'email' => 'required|email|unique:users', 'username' => 'required|unique:users', 'password' => 'required']); if (!$validator->fails()) { $user = new User(); $user->name = \Input::get('name'); $user->email = \Input::get('email'); $user->username = \Input::get('username'); $user->password = \Hash::make(\Input::get('password')); if ($user->save()) { $response["error"] = FALSE; $response["uid"] = $user->id; $response["user"]["name"] = $user->name; $response["user"]["email"] = $user->email; $response["user"]["username"] = $user->username; $response["user"]["created_at"] = $user->created_at; $response["user"]["updated_at"] = $user->updated_at; } else { $response["error"] = TRUE; $response["error_msg"] = "Data gagal disimpan!"; } } else { $messages = $validator->messages(); $response["error"] = TRUE; $response["error_msg"] = $messages->toJson(); } } else { $response["error"] = TRUE; $response["error_msg"] = "TAG required!"; } return \Response::json($response); }
public function update($id) { $db = User::find($id); $db->name = \Input::get('name'); $db->email = \Input::get('email'); $db->username = \Input::get('username'); if (\Input::has('password')) { $db->password = \Hash::make(\Input::get('password')); } $db->group = \Input::get('group'); $db->api_key = \Input::get('api_key'); $db->save(); return \Response::json(['id' => $db->id]); }
public function doProfile() { $validator = \Validator::make(\Input::all(), ['name' => 'required', 'username' => 'required|alpha_num|unique:users,username,' . \Auth::id(), 'email' => 'required|email|unique:users,email,' . \Auth::id()]); if (!$validator->fails()) { $db = User::find(\Auth::id()); $db->name = \Input::get('name'); $db->username = \Input::get('username'); $db->email = \Input::get('email'); $db->api_key = \Input::get('api_key'); if (\Input::has('password')) { $db->password = \Hash::make(\Input::get('password')); } if ($db->save()) { return \Response::json(['msg' => 'Update profil berhasil']); } else { return \Response::json(['msg' => 'Simpan data gagal!']); } } else { $messages = $validator->messages(); return \Response::json(['msg' => $messages->toJson()]); } }
<?php return ['database' => 'default', 'grant_types' => ['authorization_code' => ['class' => '\\League\\OAuth2\\Server\\Grant\\AuthCodeGrant', 'access_token_ttl' => 3600, 'auth_token_ttl' => 60], 'password' => ['class' => '\\League\\OAuth2\\Server\\Grant\\PasswordGrant', 'callback' => function ($username, $password) { if (Auth::validate(['email' => $username, 'password' => $password])) { $user = \sms\User::where('email', $username)->first(); return $user->id; } else { // dd($username); return false; } }, 'access_token_ttl' => 3600], 'client_credentials' => ['class' => '\\League\\OAuth2\\Server\\Grant\\ClientCredentialsGrant', 'access_token_ttl' => 3600], 'refresh_token' => ['class' => '\\League\\OAuth2\\Server\\Grant\\RefreshTokenGrant', 'access_token_ttl' => 3600, 'refresh_token_ttl' => 36000]], 'token_type' => 'League\\OAuth2\\Server\\TokenType\\Bearer', 'state_param' => false, 'scope_param' => false, 'scope_delimiter' => ',', 'default_scope' => null, 'access_token_ttl' => 3600, 'limit_clients_to_grants' => false, 'limit_clients_to_scopes' => false, 'limit_scopes_to_grants' => false, 'http_headers_only' => false];
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ public function create(array $data) { return User::create(['name' => $data['name'], 'email' => $data['email'], 'username' => $data['username'], 'password' => bcrypt($data['password'])]); }