public function signup() { // grappping the registered user information via request $name = Request::getParam('name'); $email = Request::getParam('email'); $pass = Request::getParam('pass'); $mobile = Request::getParam('mobile'); $tel = Request::getParam('tel'); $address = Request::getParam('address'); $diagnostic = Request::getParam('diagnostic'); $description = Request::getParam('description'); $hash = UserModel::getHash(); $user_columns = ['name' => $name, 'email' => $email, 'pass' => Hash::make($pass), 'mobile' => $mobile, 'tel' => $tel, 'address' => $address, 'hash' => $hash, 'avatar' => '']; // inserting new user if (UserModel::insert($user_columns)) { // check if there is a complain then insert it $complain = ['user_id' => UserModel::lastId(), 'diagnostic' => $diagnostic, 'description' => $description]; if (!empty($description) && !empty($diagnostic)) { ComplainModel::insert($complain); } // inserting permissions for the user as normal $permissions = ['user_id' => UserModel::lastId()]; PermissionModel::insert($permissions); // login the user $u = new User($hash); $u->login(); // redirect the user to profile page redirect(route('user.profile')); } else { Response::error(401); } }
public function delete() { $user = User::getData(); if (!empty($user->avatar)) { @unlink(Url::resource($user->avatar)); } $userFlag = UserModel::delete('id = ?', [$user->id]); $perFlag = PermissionModel::delete('user_id = ?', [$user->id]); $msgFlag = MessageModel::delete('user_id = ?', [$user->id]); $compFlag = ComplainModel::delete('user_id = ?', [$user->id]); $status = $userFlag && $perFlag && $msgFlag && $compFlag; if ($status) { $u = new User(); $u->logout(); } Response::json(['status' => $status]); }
public function delete($id) { $current = User::getData(); $admin = PermissionModel::findBy(['user_id' => $current->id, 'permission' => 'admin']); $userFlag = $perFlag = $msgFlag = $compFlag = FALSE; if ($current->id != $id && $admin) { $avatar = UserModel::id($id)->avatar; if (!empty($avatar)) { @unlink(Url::resource($avatar)); } $userFlag = UserModel::delete('id = ?', [$id]); $perFlag = PermissionModel::delete('user_id = ?', [$id]); $msgFlag = MessageModel::delete('user_id = ?', [$id]); $compFlag = ComplainModel::delete('user_id = ?', [$id]); } Response::json(['status' => $userFlag && $perFlag && $msgFlag && $compFlag]); }