public function testSearchUserSuccess() { $data = array(); $user_id = $this->_user_id; $_params = $this->_params; $_params['user_id'] = $user_id; $response = $this->_getAuth($_params); $text = $_params['text']; //get created login information $user = Profile::where('first_name', 'LIKE', '%' . $text . '%')->orWhere('last_name', 'LIKE', '%' . $text . '%')->whereNotIn('user_id', [$user_id])->get(); if ($user) { foreach ($user as $users) { $follow = Follow::where('from_id', $user_id)->where('to_id', $users->user_id)->first(); if ($follow) { $users->is_follow = true; } else { $users->is_follow = false; } if ($users->image != null) { $users->image = URL::asset($users->image); } } $data = $user->toArray(); } $this->assertNotNull($data); $this->assertEquals(array("code" => ApiResponse::OK, "data" => $data), json_decode($response->getContent(), true)); }
public function update($id) { $data = array("first_name" => Input::get("first_name"), "last_name" => Input::get("last_name"), "email" => Input::get("email"), "phone" => Input::get("phone"), "picture" => Input::file("picture"), "specialty_id" => Input::get("specialty_id"), "dating_duration" => Input::get("dating_duration")); $rules = array("first_name" => 'required|min:1|max:255', "last_name" => 'required|min:1|max:100', "email" => 'required|min:1', "phone" => 'required|min:1|max:100', "specialty_id" => 'required|min:3|max:255', "dating_duration" => 'required|min:1|max:3', "picture" => 'mimes:jpeg,gif,png'); $messages = array('required' => 'El campo :attribute es obligatorio.', 'min' => 'El campo :attribute no puede tener menos de :min carácteres.', 'email' => 'El campo :attribute debe ser un email válido.', 'max' => 'El campo :attribute no puede tener más de :max carácteres.', 'numeric' => 'El campo :attribute debe contener solo numeros', 'mimes' => 'El formato de la imagen logo debe ser jpg, git, png'); $validation = Validator::make(Input::all(), $rules, $messages); //si la validación falla redirigimos al formulario de registro con los errores //y con los campos que nos habia llenado el usuario if ($validation->fails()) { return Redirect::to('/doctor/profile')->withErrors($validation)->withInput(); } else { $doctor = Doctor::find($id); $agenda = Agenda::where('doctor_id', $doctor->id)->first(); $agenda->dating_duration = Input::get("dating_duration"); $agenda->save(); $espes = explode(',', Input::get("specialty_id")); $espeuok = ''; foreach ($espes as $espe) { $very = Specialty::where('name_es', $espe)->first(); if ($very) { $espeuok = $espeuok . ',' . $very->id; } } $doctor->specialty_id = $espeuok; $doctor->save(); $user = User::find($doctor->user_id); $user->first_name = $data['first_name']; $user->last_name = $data['last_name']; $user->save(); $profile = Profile::where('user_id', $doctor->user_id)->first(); if (Input::file('picture') != NULL) { //agrega imagen de logo $file_logo = Input::file('picture'); $ext = Input::file('picture')->getClientOriginalExtension(); $nameIMG = date('YmdHis'); $logo = $nameIMG . '.' . $ext; $logo = 'assets/doctor/images/profile_pic/profile_' . $logo; $profile->picture = $logo; } $profile->phone = Input::get("phone"); $profile->save(); if ($profile) { if (Input::file('picture') != NULL) { $file_logo->move("assets/doctor/images/profile_pic/", $logo); } return Redirect::to('/doctor/profile')->withFlash_message("Guardado Exitosamente"); } else { return Redirect::to('/doctor/profile')->withErrors("Error")->withInput(); } } }
public function post_manage() { $user_fullname = Input::get('user'); $year_id = Input::get('year_id'); $executive_id = Input::get('executive_id'); $profile = Profile::where('full_name', '=', $user_fullname)->first(); if (!$profile) { return Redirect::to('rms/executives/manage/' . $executive_id)->with('warning', 'Please enter a member'); } $user = $profile->user; if (!$user->is_part_of_exec($year_id, $executive_id)) { $user->executives()->attach($executive_id, array('non_executive' => Input::get('non_executive', 0), 'year_id' => $year_id)); return Redirect::to('rms/executives/manage/' . $executive_id)->with('success', 'Successfully added member to executive'); } else { return Redirect::to('rms/executives/manage/' . $executive_id)->with('warning', 'They are already a member of that executive'); } }
/** * @param $id */ public function allUserData($id, $mode = 'show') { if (!($user = User::find($id))) { abort(404); } $name = $user->full_name; if (!($fullProfile = Profile::where('user_id', '=', $id)->first())) { $fullProfile = new Profile(); } $cityLiving = $this->placeLiving($fullProfile->place_living_id); $cityFrom = $this->placeFrom($fullProfile->place_from_id); $languages_high = Language::where('profile_id', '=', $fullProfile->id)->where('level', '=', 'advanced')->get(); $languages_med = Language::where('profile_id', '=', $fullProfile->id)->where('level', '=', 'intermediate')->get(); $languages_low = Language::where('profile_id', '=', $fullProfile->id)->where('level', '=', 'basic')->get(); //Avatar is optional if ($user->avatar) { $avatar = $user->avatar; } if ($mode == 'show' || $mode == 'references') { $references = Reference::where('profile_user_id', '=', $id)->with(['user'])->orderBy('updated_at', 'DES')->get(); $age = $user->age; $owner = \Auth::id() == $id; $gender = $user->gender; $places = $user->placesWanted; $placesVisited = $user->placesVisited; $avg = Reference::where('profile_user_id', '=', $id)->avg('grade'); $ref = false; $fav = boolval(Favorites::where('owner_id', \Auth::id())->where('user_id', $id)->first()); if ($mode == 'references') { $ref = true; } return compact('fullProfile', 'references', 'name', 'avatar', 'ref', 'avg', 'cityFrom', 'cityLiving', 'age', 'gender', 'id', 'owner', 'fav', 'languages_high', 'languages_med', 'languages_low', 'places', 'placesVisited'); } else { if ($mode == 'edit') { return compact('fullProfile', 'cityFrom', 'cityLiving', 'name', 'avatar', 'id', 'languages_high', 'languages_med', 'languages_low'); } else { return abort(404); } } }
public static function getProfile($user_id, $title, $id, $rating_id, $updated_at) { $profile = Profile::where('user_id', $user_id)->first(); $data = array('first_name' => $profile->first_name, 'last_name' => $profile->last_name, 'avatar' => URL::asset($profile->image), 'title' => $title, 'id' => $id, 'rating_id' => $rating_id, 'updated_at' => $updated_at); return $data; }
<form> <table class="table table-striped" id="table-example"> <thead> <tr> <th class="text-center">Imagen</th> <th class="text-center">Name</th> <th class="text-center">Email</th> <th class="text-center">Phone</th> <th class="text-center">Citas pendientes/Historia de citas</th> </tr> </thead> <tbody align="center"> @foreach($patients as $d) <?php $user = User::find($d->user_id); $profile = Profile::where('user_id', $user->id)->first(); ?> <tr class="odd gradeX"> <td><img class="circle profile-table" src="@if($profile->picture!="") {{url($profile->picture)}} @else http://agenda.dev/assets/doctor/images/profile_pic/default.png @endif" alt=""></td> <td>{{$user->getFullName()}}</td> <td>{{$user->email}}</td> <td>{{$profile->phone}}</td> <td><a href="{{url('/doctor/agenda/'.$d->agenda_id.'/patient/'.$d->patient_id.'/appointments-pending')}}" type="button" class="btn btn-info btn-transparent" data-toggle="tooltip" data-placement="left" title="Citas Pendientes"><i class="fa fa-clock-o"></i> Pendientes</a> <a href="{{url('/doctor/agenda/'.$d->agenda_id.'/patient/'.$d->patient_id.'/appointments-history')}}" type="button" class="btn btn-info btn-transparent" data-toggle="tooltip" data-placement="left" title="Historia de citas"><i class="fa fa-clock-o"></i> Historia</a></td> </tr> @endforeach </tbody> </table> </form> </div> </section>
public function loginWithGithub() { $code = Input::get('code'); $githubService = OAuth::consumer('Github'); if (!empty($code)) { try { $token = $githubService->requestAccessToken($code); $result = json_decode($githubService->request('user'), true); } catch (Exception $e) { die("Too many requests, access denied by Github. Please wait a while."); } $profile = Profile::where('uid', '=', $result['id'])->first(); if (empty($profile)) { $user = new User(); $user->name = $result['name']; $user->email = $result['email']; $user->photo = $result['avatar_url']; $user->save(); $profile = new Profile(); $profile->uid = $result['id']; // $profile->access_token = $fb->requestAccessToken( $code ); $profile->username = $result['login']; $profile->gender = $result['bio']; $profile = $user->profiles()->save($profile); } $profile->save(); $user = $profile->user; Auth::login($user); return Redirect::to('/')->with('message', 'Logged in with Facebook'); } else { // get githubService authorization $url = $githubService->getAuthorizationUri(); return Redirect::to((string) $url); } }
public function destroy($id) { $doctor = Doctor::find($id); $userId = $doctor->user_id; $doctor->delete(); $profile = Profile::where('user_id', $userId)->first(); $profile->delete(); $user = User::find($userId); $user->delete(); if ($user) { return Redirect::back()->withConfirm("Eliminado Exitosamente"); } else { return Redirect::back()->withErrors("Error"); } }
public static function picture() { $user = Sentry::getUser(); $profile = Profile::where('user_id', $user->id)->first(); return $profile->picture; }
public function storeLogin() { $inputs = array('identity' => Input::get('identity'), 'password' => Input::get('password')); //Since user can enter username,email we cannot have email validator $rules = array('identity' => 'required|min:4|max:32', 'password' => 'required|min:6'); //Find is that username or password and change identity validation rules //Lets use regular expressions if (filter_var(Input::get('identity'), FILTER_VALIDATE_EMAIL)) { //It is email $rules['identity'] = 'required|min:4|max:32|email'; } else { //It is username . Check if username exist in profile table if (Profile::where('username', Input::get('identity'))->count() > 0) { //User exist so get email address $user = Profile::where('username', Input::get('identity'))->first(); $inputs['identity'] = $user->email; } else { Session::flash('error_msg', 'User does not exist'); return Redirect::to('/login')->withInput(Input::except('password')); } } $v = Validator::make($inputs, $rules); if ($v->fails()) { return Redirect::to('/login')->withErrors($v)->withInput(Input::except('password')); } else { try { //Try to authenticate user $user = Sentry::getUserProvider()->findByLogin(Input::get('identity')); $throttle = Sentry::getThrottleProvider()->findByUserId($user->id); $throttle->check(); //Authenticate user $credentials = array('email' => Input::get('identity'), 'password' => Input::get('password')); //For now auto activate users $user = Sentry::authenticate($credentials, false); //At this point we may get many exceptions lets handle all user management and throttle exceptions } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { Session::flash('error_msg', 'Login field is required.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { Session::flash('error_msg', 'Password field is required.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { Session::flash('error_msg', 'Wrong password, try again.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { Session::flash('error_msg', 'User was not found.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { Session::flash('error_msg', 'User is not activated.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { Session::flash('error_msg', 'User is suspended '); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { Session::flash('error_msg', 'User is banned.'); return Redirect::to('/login'); } Session::flash('success_msg', 'Loggedin Successfully'); return Redirect::to('/'); } }
public function update($id) { $data = array("first_name" => Input::get("first_name"), "last_name" => Input::get("last_name"), "email" => Input::get("email"), "phone" => Input::get("phone"), "picture" => Input::file("picture"), "password" => Input::get("password"), "password_confirmation" => Input::get("password_confirmation")); if (Input::get("password") != "") { $rules = array("first_name" => 'required|min:1|max:255', "last_name" => 'required|min:1|max:100', "email" => 'required|email', "phone" => 'required|min:1|max:100', "picture" => 'mimes:jpeg,gif,png', 'password' => 'confirmed|min:6'); } else { $rules = array("first_name" => 'required|min:1|max:255', "last_name" => 'required|min:1|max:100', "email" => 'required|email', "phone" => 'required|min:1|max:100', "picture" => 'mimes:jpeg,gif,png'); } $messages = array('required' => 'El campo :attribute es obligatorio.', 'min' => 'El campo :attribute no puede tener menos de :min carácteres.', 'email' => 'El campo :attribute debe ser un email válido.', 'max' => 'El campo :attribute no puede tener más de :max carácteres.', 'numeric' => 'El campo :attribute debe contener solo numeros', 'mimes' => 'El formato de la imagen logo debe ser jpg, git, png', 'unique' => 'El :attribute ingresado ya esta siendo usaddo por otro usuario.', 'confirmed' => 'La confirmación del :attribute no coincide'); $validation = Validator::make(Input::all(), $rules, $messages); //si la validación falla redirigimos al formulario de registro con los errores //y con los campos que nos habia llenado el usuario if ($validation->fails()) { return Redirect::to('/clinic/users/' . $id . '/edit')->withErrors($validation)->withInput(); } else { $user = User::find($id); $user->first_name = Input::get("first_name"); $user->last_name = Input::get("last_name"); $user->email = Input::get("email"); if (Input::get("password") != "") { $user->password = Input::get("password"); } $user->save(); $profile = Profile::where('user_id', $id)->first(); if (Input::file('picture') != NULL) { //agrega imagen de logo $file_logo = Input::file('picture'); $ext = Input::file('picture')->getClientOriginalExtension(); $nameIMG = date('YmdHis'); $logo = $nameIMG . '.' . $ext; $logo = 'assets/doctor/images/profile_pic/profile_' . $logo; $file_logo->move("assets/doctor/images/profile_pic/", $logo); $profile->picture = $logo; } $profile->lang = Input::get("lang"); $profile->phone = Input::get("phone"); $profile->save(); if ($profile) { return Redirect::to('/clinic/users/')->withFlash_message("Guardado Exitosamente"); } else { return Redirect::to('/clinic/users/' . $id . '/edit')->withErrors("Error")->withInput(); } } }
function member($id) { if (!is_numeric($id)) return false; if ($this->tank_auth->get_user_id() == $id && $this->uri->segment(3) != 'you') redirect('/admin/members/you/'); if ($this->tank_auth->is_admin() || $this->tank_auth->is_group('mod')) $can_edit = true; else $can_edit = false; if ($this->tank_auth->get_user_id() == $id) $can_edit_limited = true; else $can_edit_limited = false; if ($this->input->post() && ( $can_edit || $can_edit_limited)) { $profile = new Profile($id); $profile->from_array($this->input->post(), array('display_name', 'twitter', 'bio'), TRUE); } $this->viewdata["function_title"] = _("Member"); $user = new User($id); if ($user->result_count() == 0) return false; if($this->tank_auth->is_allowed()) { $table = ormer($user); //$table = tabler($table, TRUE, $can_edit); not even admins should edit $table = tabler($table, TRUE, FALSE); $data['table'] = $table; } else { $data["table"] = ""; } $data['user'] = $user; $profile = new Profile(); $profile->where('user_id', $id)->get(); $profile_table = ormer($profile); $data['profile'] = tabler($profile_table, TRUE, $can_edit); $data['can_edit'] = $can_edit; $this->viewdata["main_content_view"] = $this->load->view('auth/user', $data, TRUE); $this->load->view("admin/default", $this->viewdata); }
public function testGetProfileWishlishSucsses() { $this->setUpWishlist(); $user_id = $this->_user_id; $response = $this->action('GET', 'ProfileController@get_profile_wishlist_user', array('user_id' => $user_id)); $page = 1; $limit = 10; $profile = Profile::where('user_id', $user_id)->first(); if ($profile->image != null) { $profile->image = URL::asset($profile->image); } $wishlist = Wishlist::where('user_id', $user_id)->with('wine')->forPage($page, $limit)->get(); foreach ($wishlist as $wishlists) { $wishlists->winery = Winery::where('id', $wishlists->wine->winery_id)->first()->toArray(); if ($wishlists->wine->image_url != null) { $wishlists->wine->image_url = URL::asset($wishlists->wine->image_url); } if ($wishlists->wine->wine_flag != null) { $wishlists->wine->wine_flag = URL::asset($wishlists->wine->wine_flag); } } $data = $wishlist; $this->assertEquals(array("code" => ApiResponse::OK, "data" => $data->toArray()), json_decode($response->getContent(), true)); }
public function testCreateCommentSuccess() { $_params = $this->_params; $_params['user_id'] = $this->_user_id; $response = $this->_getAuth($_params); //get created login information $comment_infor = Comment::get(array('user_id', 'rating_id', 'content', 'updated_at', 'created_at', 'id'))->last(); $profile = Profile::where('user_id', $comment_infor->user_id)->first(); if ($profile->image != null) { $comment_infor->avatar_user = URL::asset($profile->image); } else { $comment_infor->avatar_user = $profile->image; } $comment_infor->first_name = $profile->first_name; $comment_infor->last_name = $profile->last_name; $this->assertNotNull($comment_infor); $this->assertEquals(array("code" => ApiResponse::OK, "data" => $comment_infor->toArray()), json_decode($response->getContent(), true)); }
function member($id) { // don't troll us with other than numbers as ID, throw 404 in case if (!is_numeric($id)) { show_404(); } // if the user doesn't exist throw 404 $user = new User($id); if ($user->result_count() != 1) { show_404(); } // if the user is clicking on himself, send him to the you page. // the you method sends back here, so the user will still see the rest. // the second part of the if makes sure that if "member" method is called from "you" // the user is not redirected to "you" again if ($this->tank_auth->get_user_id() == $id && $this->uri->segment(3) != 'you') { redirect('/account/profile/'); } // give admins and mods ability to edit user profiles if ($this->input->post() && $this->tank_auth->is_allowed()) { $profile = new Profile($id); if ($profile->result_count() == 1) { $profile->from_array($this->input->post(), array('display_name', 'twitter', 'bio'), TRUE); } } // set the subtitle $this->viewdata["function_title"] = '<a href="' . site_url("admin/members") . '">' . _('Members') . '</a>'; // create a table with user login name and email $table = ormer($user); $table = tabler($table, TRUE, FALSE); $data['table'] = $table; // let's give the user object to the view $data['user'] = $user; // grab the profile and put it in a table $profile = new Profile(); $profile->where('user_id', $id)->get(); $profile_table = ormer($profile); $data['profile'] = tabler($profile_table, TRUE, $this->tank_auth->is_allowed() || $this->uri->segment(3) != 'you'); $this->viewdata["extra_title"][] = $user->username; // print out $this->viewdata["main_content_view"] = $this->load->view('admin/members/user', $data, TRUE); $this->load->view("admin/default", $this->viewdata); }
public function checkAndSave($data) { // flow: // 1. profile by uid? // yes > update profile // no > create profile // 2. user account by email? // yes > update user // no > create user account // 3. log in user $profile = Profile::where('uid', $data['uid'])->first(); if (!empty($profile)) { //update profile $profile->provider = Request::segment(2); // $profile->first_name = $data['first_name']; // $profile->last_name = $data['last_name']; // $profile->username = $data['username']; // $profile->email = $data['email']; // $profile->uid = $data['uid']; // $profile->link = $data['link']; // $profile->location = $data['location']; // $profile->about = $data['about']; // $profile->pic = $data['pic']; // $profile->code = $data['code']; $profile->field1 = Input::get('code'); // $profile->field2 = $data['field2']; // $profile->field3 = $data['field3']; // $profile->field4 = $data['field4']; // $profile->field5 = $data['field5']; $profile->update($data); } else { // create profile $profile = new Profile(); $data['provider'] = Request::segment(2); $data['field1'] = Input::get('code'); // $data->field2 = $data['field2']; // $data->field3 = $data['field3']; // $data->field4 = $data['field4']; // $data->field5 = $data['field5']; $x = $profile->insertGetId($data); // $x = $profile->create($data)->id; // return var_dump($x); } if ($user = User::where('email', $data['email'])->first()) { // Find the user using the user id or e-mail //update user if we have new values $user_update['first_name'] = $data['first_name'] != '' ? $data['first_name'] : $user['first_name']; $user_update['first_name'] = $user['first_name'] != '' ? $user_update['first_name'] : $data['username']; //case git $user_update['last_name'] = $data['last_name'] != '' ? $data['last_name'] : $user['last_name']; $user_update['email'] = $data['email'] != '' ? $data['email'] : $user['email']; $user_update['pic'] = $data['pic'] != '' ? $data['pic'] : $user['pic']; $user_update['pic'] = $user['pic'] != '' ? $user['pic'] : $user_update['pic']; //no need to update $user_update['location'] = $data['location'] != '' ? $data['location'] : $user['location']; $user_update['elevator'] = substr($data['about'], 100) != '' ? '' : $data['about']; //elevator must not > 100 $user_update['elevator'] = $user['elevator'] != '' ? $user['elevator'] : $user_update['elevator']; //no need to update $user_update['about'] = $user['about'] != '' ? $user['about'] : $data['about']; //no need to update User::find($user->id)->update($user_update); } elseif (empty($data['email'])) { return false; } else { // no user, register onesubstr($data['about'], 100) != '' ? '' : $data['about']; $user = new User(); $user->email = $data['email']; $user->first_name = $data['first_name']; $user->last_name = $data['last_name']; $user->pic = $data['pic']; $user->elevator = substr($data['about'], 100) != '' ? '' : $data['about']; $user->about = substr($data['about'], 100) != '' ? $data['about'] : ''; $user->location = $data['location']; $user->public = 'on'; $user->activated = 1; // return var_dump('trying to create user: </br>'.$user); $user->save(); } $user_interface = Sentry::findUserById($user->id); Sentry::login($user_interface, false); return $user->id; // return var_dump(Sentry::getUser()->id); // $code = Input::get('code'); // dd($code); // return var_dump($code); // if (strlen($code) == 0) return Redirect::to('/')->with('message', 'There was an error communicating with Facebook'); // $uid = $user['uid']; // if ($uid == 0) return Redirect::to('/')->with('message', 'There was an error'); // $data = $facebook->api('/me'); // dd($data); }
public static function getProfileWishlistUser($user_id) { $error_code = ApiResponse::OK; $pagination = ApiResponse::pagination(); if ($pagination == false) { $error_code = ApiResponse::URL_NOT_EXIST; $data = ApiResponse::getErrorContent(ApiResponse::URL_NOT_EXIST); } else { $page = $pagination['page']; $limit = $pagination['limit']; if (User::where('user_id', $user_id)->first()) { $profile = Profile::where('user_id', $user_id)->first(); if ($profile->image != null) { $profile->image = URL::asset($profile->image); } $wishlists = Wishlist::where('user_id', $user_id)->with('wine')->forPage($page, $limit)->get(); if (count($wishlists) == 0) { $data = array(); } else { foreach ($wishlists as $wishlist) { $wishlist->winery = Winery::where('id', $wishlist->wine->winery_id)->first(); if ($wishlist->wine->image_url != null) { $wishlist->wine->image_url = URL::asset($wishlist->wine->image_url); } if ($wishlist->wine->wine_flag != null) { $wishlist->wine->wine_flag = URL::asset($wishlist->wine->wine_flag); } } $data = $wishlists->toArray(); } } else { $error_code = ApiResponse::UNAVAILABLE_USER; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_USER); } } return array("code" => $error_code, "data" => $data); }
public static function deleteComment($rating_id, $id) { $comment = Comment::where('id', '=', $id)->first(); $error_code = ApiResponse::OK; if (Rating::where('id', $rating_id)->first()) { if ($comment) { $comment_profile = Profile::where('user_id', $comment->user_id)->first(); if ($comment_profile != null) { $comment_profile->comment_count = $comment_profile->comment_count - 1; $comment_profile->save(); } //update comment_count on rating $comment_rating = Rating::where('id', $comment->rating_id)->first(); if ($comment_rating != null) { $comment_rating->comment_count = $comment_rating->comment_count - 1; $comment_rating->save(); $comment->delete(); } $data = 'Comment deleted'; } else { $error_code = ApiResponse::UNAVAILABLE_COMMENT; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_COMMENT); } } else { $error_code = ApiResponse::UNAVAILABLE_RATING; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING); } return array("code" => $error_code, "data" => $data); }
public function createOAuthProfile($userProfile) { if (isset($userProfile->username)) { $username = strlen($userProfile->username) > 0 ? $userProfile->username : ""; } if (isset($userProfile->screen_name)) { $username = strlen($userProfile->screen_name) > 0 ? $userProfile->screen_name : ""; } if (isset($userProfile->displayName)) { $username = strlen($userProfile->displayName) > 0 ? $userProfile->displayName : ""; } $email = strlen($userProfile->email) > 0 ? $userProfile->email : ""; $email = strlen($userProfile->emailVerified) > 0 ? $userProfile->emailVerified : ""; $password = $this->generatePassword(); if (Profile::where('email', $email)->count() <= 0) { $user = Sentry::register(array('email' => $email, 'password' => $password), true); try { $user_group = Sentry::findGroupById(1); } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { $this->createGroup('users'); $this->createGroup('admin'); $user_group = Sentry::findGroupById(1); } $user->addGroup($user_group); $profile = new Profile(); $profile->user_id = $user->getId(); $profile->email = $email; $profile->username = $username; $profile->save(); } //Login user //Try to authenticate user try { $user = Sentry::findUserByLogin($email); $throttle = Sentry::getThrottleProvider()->findByUserId($user->id); $throttle->check(); //Authenticate user $credentials = array('email' => $email, 'password' => Input::get('password')); Sentry::login($user, false); //At this point we may get many exceptions lets handle all user management and throttle exceptions } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { Session::flash('error_msg', 'Login field is required.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Users\PasswordRequiredException $e) { Session::flash('error_msg', 'Password field is required.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Users\WrongPasswordException $e) { Session::flash('error_msg', 'Wrong password, try again.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { Session::flash('error_msg', 'User was not found.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Users\UserNotActivatedException $e) { Session::flash('error_msg', 'User is not activated.'); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e) { Session::flash('error_msg', 'User is suspended '); return Redirect::to('/login'); } catch (Cartalyst\Sentry\Throttling\UserBannedException $e) { Session::flash('error_msg', 'User is banned.'); return Redirect::to('/login'); } }
function is_group($group_name) { if (!$this->is_logged_in()) { return FALSE; } if ($group_name == 'member') { return TRUE; } if (!isset($this->cached["group"][$group_name])) { $group = new Group(); $group->where('name', $group_name)->get(); if ($group->result_count() != 1) { log_message('error', 'tank_auth:is_group: using non-existent group name'); return FALSE; } $this->cached["group"][$group_name] = $group; } if (!isset($this->cached["profile"])) { $profile = new Profile(); $profile->where('user_id', $this->get_user_id())->limit(1)->get(); $this->cached["profile"] = $profile; } if ($this->cached["group"][$group_name]->id == $this->cached["profile"]->group_id) { return TRUE; } return FALSE; }
<?php /** * Profile Controller */ $app->group('/profiles', function () use($app) { $app->post('/', function () use($app) { $data = json_decode($app->request->getBody(), true); $results = []; if (validatedKey($data['user'])) { $results['profile'] = Profile::where('user_id', '=', $data['user']['id'])->first(); $results["success"] = "true"; } else { $results["success"] = "false"; } echo json_encode($results); }); $app->get('/show/:id', function ($id) use($app) { $results = []; $results["profile"] = Profile::find($id); $results["success"] = "true"; echo json_encode($results); }); $app->post('/form', function () use($app) { $data = json_decode($app->request->getBody(), true); $results = []; $results["success"] = "false"; if (validatedKey($data['user'])) { if (isset($data['profile']['id'])) { Profile::find($data['profile']['id'])->update($data['profile']); $results["value"] = "Update";
public function create_administrative_staff() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["actions"] = Session::get('actions'); if (in_array('side_nuevo_personal_administrativo', $data["actions"])) { // Validate the info, create rules for the inputs $attributes = array('dni' => 'DNI del Personal Administrativo', 'names' => 'Nombres del Personal Administrativo', 'lastname' => 'Apellidos del Personal Administrativo', 'birthdate' => 'Fecha de nacimiento', 'email' => 'E-mail', 'telephone' => 'Teléfono o Celular'); $messages = array(); $rules = array('dni' => 'required|digits:8|unique:users,dni,NULL,id,deleted_at,NULL', 'names' => 'required|alpha_num_dash|max:45', 'lastname' => 'required|alpha_num_dash|max:45', 'email' => 'required|email|max:100|unique:users,email,NULL,id,deleted_at,NULL'); // Run the validation rules on the inputs from the form $validator = Validator::make(Input::all(), $rules, $messages, $attributes); // If the validator fails, redirect back to the form if ($validator->fails()) { return Redirect::to('people/new_administrative_staff')->withErrors($validator)->withInput(Input::all()); } else { // se crea el usuario primero $user = new User(); $user->dni = Input::get('dni'); $e = Input::get('email'); if ($e != '') { $user->email = $e; } $user->password = Hash::make('12345678'); $user->save(); $user->profiles()->attach(Profile::where('name', '=', 'Personal Administrativo')->first()->id); $admin_staff = new AdministrativeStaff(); $admin_staff->names = Input::get('names'); $admin_staff->lastname = Input::get('lastname'); $b = Input::get('birthdate'); if ($b != '') { $admin_staff->birthdate = date('Y-m-d', strtotime($b)); } $admin_staff->telephone = Input::get('telephone'); $admin_staff->user_id = $user->id; $admin_staff->save(); Session::flash('message', 'Se creó correctamente el Personal Administrativo.'); // Llamo a la función para registrar el log de auditoria $log_description = "Se creó el Personal Administrativo con id: {{$admin_staff->id}}"; Helpers::registerLog(3, $log_description); return Redirect::to('people/list_administrative_staff'); } } else { // Llamo a la función para registrar el log de auditoria $log_description = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'"; Helpers::registerLog(10, $log_description); Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.'); return Redirect::to('/dashboard'); } } else { return View::make('error/error'); } }
public function postAdminProfile() { $data = array("first_name" => Input::get("first_name"), "last_name" => Input::get("last_name"), "email" => Input::get("email"), "phone" => Input::get("phone"), "picture" => Input::file("picture")); $rules = array("first_name" => 'required|min:1|max:255', "last_name" => 'required|min:1|max:100', "email" => 'required|min:1', "phone" => 'required|min:1|max:100', "picture" => 'mimes:jpeg,gif,png'); $messages = array('required' => 'El campo :attribute es obligatorio.', 'min' => 'El campo :attribute no puede tener menos de :min carácteres.', 'email' => 'El campo :attribute debe ser un email válido.', 'max' => 'El campo :attribute no puede tener más de :max carácteres.', 'numeric' => 'El campo :attribute debe contener solo numeros', 'mimes' => 'El formato de la imagen logo debe ser jpg, git, png'); $validation = Validator::make(Input::all(), $rules, $messages); //si la validación falla redirigimos al formulario de registro con los errores //y con los campos que nos habia llenado el usuario if ($validation->fails()) { return Redirect::back()->withErrors($validation)->withInput(); } else { $user = Sentry::getUser(); $user->first_name = $data['first_name']; $user->last_name = $data['last_name']; $user->save(); $profile = Profile::where('user_id', $user->id)->first(); if (Input::file('picture') != NULL) { //agrega imagen de logo $file_logo = Input::file('picture'); $ext = Input::file('picture')->getClientOriginalExtension(); $nameIMG = date('YmdHis'); $logo = $nameIMG . '.' . $ext; $logo = 'assets/doctor/images/profile_pic/profile_' . $logo; $profile->picture = $logo; } $profile->phone = Input::get("phone"); $profile->save(); if ($profile) { if (Input::file('picture') != NULL) { $file_logo->move("assets/doctor/images/profile_pic/", $logo); } return Redirect::back()->withFlash_message("Guardado Exitosamente"); } else { return Redirect::back()->withErrors("Error")->withInput(); } } }
<script src="js/jquery.pep.js"></script> <script src="js/jquery.infinitedrag/jquery.infinitedrag.js"></script> <script src="js/vex/js/vex.combined.min.js"></script> <script>vex.defaultOptions.className = 'vex-theme-os';</script> <link rel="stylesheet" href="js/vex/css/vex.css" /> <link rel="stylesheet" href="js/vex/css/vex-theme-os.css" /> <link rel="stylesheet" href="js/shepherd/css/shepherd-theme-arrows.css" /> <script src="js/shepherd/shepherd.min.js"></script> <?php $allowed = false; $user = Auth::user(); $profile = Profile::where('user_id', $user->id)->orderBy('updated_at', 'DESC')->first(); $logtext = '[' . date('d-M-Y H:i:s') . '] ' . $profile->username . PHP_EOL; file_put_contents(storage_path() . '/logs/facebook.log', $logtext, FILE_APPEND); ?> <!-- build:js js/otworlds.min.js --> <script src="js/otworlds.mapeditor.js"></script> <script src="js/otworlds.materials.js"></script> <script src="js/otworlds.minimap.js"></script> <script src="js/otworlds.multiplayer.js"></script> <script src="js/otworlds.tile.js"></script> <script src="js/otworlds.tiles.js"></script> <script src="js/otworlds.shepherd.js"></script> <!-- endbuild --> <script> var TogetherJSConfig_siteName = 'OTWorlds';
return $response->write('{"msg":"Email adresi kullanılıyor !"}')->withHeader('Content-type', 'application/json'); } return $response->getBody()->write('{"msg":"Kayıt esnasında bir hata oluştu !"}'); } return $response->withHeader('Content-type', 'application/json'); }); $app->group('/user', function () { // id'den user profili $this->get('/{id:[0-9]+}/profile', function ($request, $response, $args) { $profile = Profile::where('user_id', '=', $args['id'])->where('deleted', 0)->get()->first(); return $response->getBody()->write(json_encode($profile) . ' '); })->setName('user_profile'); // id'den user profili $this->get('/profile', function ($request, $response, $args) { $token = Token::where("token", $request->getHeader('token')[0])->where('deleted', 0)->get()->first(); $profile = Profile::where('user_id', '=', $token->user_id)->get()->first(); return $response->getBody()->write(json_encode($profile) . ' '); })->setName('user_profile'); // profili güncelle $this->put('/profile', function ($request, $response, $args) { $token = Token::where("token", $request->getHeader('token')[0])->get()->first(); $user = $token->user(); $profile = $user->profile(); $newProfile = json_decode($request->getBody()); $profile->user_id = $user->user_id; $profile->firstname = $newProfile->firstname; $profile->lastname = $newProfile->lastname; $profile->about = $newProfile->about; $profile->birthdate = $newProfile->birthdate; $profile->last_update_date = date("YmdHi"); try {
public static function searchUserFromUserName($input) { $error_code = ApiResponse::OK; $data = $input; $user_id = Session::get('user_id'); if (!empty($input['text'])) { $text = $input['text']; $users = Profile::where('first_name', 'LIKE', '%' . $text . '%')->orWhere('last_name', 'LIKE', '%' . $text . '%')->whereNotIn('user_id', [$user_id])->get(); if ($users) { foreach ($users as $user) { $follow = Follow::where('from_id', $user_id)->where('to_id', $user->user_id)->first(); if ($follow) { $user->is_follow = true; } else { $user->is_follow = false; } if ($user->image != null) { $user->image = URL::asset($user->image); } } $data = $users->toArray(); } } else { $error_code = ApiResponse::MISSING_PARAMS; } return array("code" => $error_code, "data" => $data); }
public static function getListFollowing($user_id) { $error_code = ApiResponse::OK; $data = array(); if (User::where('user_id', $user_id)) { $pagination = ApiResponse::pagination(); if ($pagination == false) { $error_code = ApiResponse::URL_NOT_EXIST; $data = ApiResponse::getErrorContent(ApiResponse::URL_NOT_EXIST); } else { $page = $pagination['page']; $limit = $pagination['limit']; $users_followers = Follow::where('from_id', $user_id)->forPage($page, $limit)->get(); if ($users_followers) { foreach ($users_followers as $user_follower) { $user = Profile::where('user_id', $user_follower->to_id)->first(); if ($user) { if ($user->image != null) { $user->image = URL::asset($user->image); } $user_follower = $user; $data[] = $user_follower; } } } } } else { $error_code = ApiResponse::UNAVAILABLE_USER; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_USER); } return array("code" => $error_code, "data" => $data); }
<tr> <th class="text-center">Imagen</th> <th class="text-center">Name</th> <th class="text-center">Email</th> <th class="text-center">Phone</th> <th class="text-center">Status</th> <th class="text-center">Confirmacion Automatica</th> <th class="text-center">Horarios/Calendario</th> <th class="text-center">Editar/Eliminar</th> </tr> </thead> <tbody align="center"> @foreach($doctors as $d) <?php $doc = User::find($d->user_id); $profile = Profile::where('user_id', $d->user_id)->first(); $age = Agenda::where('doctor_id', $d->id)->first(); ?> <tr class="odd gradeX"> <td><img class="circle profile-table" src="@if($profile->picture!="") {{url($profile->picture)}} @else http://agenda.dev/assets/doctor/images/profile_pic/default.png @endif" alt=""></td> <td>{{$doc->getFullName()}}</td> <td>{{$doc->email}}</td> <td>{{$profile->phone}}</td> <td> @if($d->state!=0) <div class="col-sm-4 iSwitch flat-switch"> <div class="switch switch-small"> <input type="checkbox" class="checkAjax" data-toggle="tooltip" data-placement="left" title="Activado" state="{{$d->id}}" checked> </div> </div><!-- //col-sm-4 --> @else
function _submit($post) { // validate the inputted data with the validation class $this->load->library('form_validation'); $this->form_validation->set_rules('db_type', _('Database type'), ''); $this->form_validation->set_rules('db_hostname', _('Database hostname'), ''); $this->form_validation->set_rules('db_name', _('Database name'), ''); $this->form_validation->set_rules('db_username', _('Database username'), ''); $this->form_validation->set_rules('db_password', _('Database password'), ''); $this->form_validation->set_rules('db_prefix', _('Database prefix'), ''); $this->form_validation->set_rules('username', _('Administrator username'), 'required|min_length[4]|max_length[20]'); $this->form_validation->set_rules('password', _('Administrator password'), 'required|min_length[5]|max_length[20]'); $this->form_validation->set_rules('email', _('Administrator email'), 'required|valid_email'); if ($this->form_validation->run() == FALSE) { return false; } if (!is_writable('content') && is_writable('content/themes')) { return false; } // we need to check database connection, and to do that we need to connect in first place $config["hostname"] = $post["db_hostname"]; $config["database"] = $post["db_name"]; $config["username"] = $post["db_username"]; $config["password"] = $post["db_password"]; $config["dbprefix"] = $post["db_prefix"]; $config['dbdriver'] = $post["db_type"]; $config['pconnect'] = FALSE; $config['db_debug'] = FALSE; $config['cache_on'] = FALSE; $config['cachedir'] = ""; $config['char_set'] = "utf8"; $config['dbcollat'] = "utf8_general_ci"; // load the co $this->db = $this->load->database($config, TRUE); // without conn_id we're not connected to the database if ($this->db->conn_id == "") { // unable to connect set_notice('error', _('Connection with database not enstabilished: check the database fields.')); return false; } // pick the sample config and replace entries so we can insert the database $config = read_file('assets/config.sample.php'); $config = str_replace("\$db['default']['dbdriver'] = ''", "\$db['default']['dbdriver'] = '" . addslashes($post["db_type"]) . "'", $config); $config = str_replace("\$db['default']['hostname'] = 'localhost'", "\$db['default']['hostname'] = '" . addslashes($post["db_hostname"]) . "'", $config); $config = str_replace("\$db['default']['username'] = ''", "\$db['default']['username'] = '******'", $config); $config = str_replace("\$db['default']['password'] = ''", "\$db['default']['password'] = '******'", $config); $config = str_replace("\$db['default']['database'] = ''", "\$db['default']['database'] = '" . addslashes($post["db_name"]) . "'", $config); $config = str_replace("\$db['default']['dbprefix'] = 'fs_'", "\$db['default']['dbprefix'] = '" . addslashes($post["db_prefix"]) . "'", $config); // create a random string of 20 letters and numbers for the encryption key $random_string = random_string(20); $this->config->set_item('encryption_key', $random_string); $config = str_replace("\$config['encryption_key'] = ''", "\$config['encryption_key'] = '" . addslashes($random_string) . "'", $config); // check if a manual config file must be made manually (due to no permissions on FoOlSlide root) $manual_config = FALSE; if (!write_file('config.php', $config)) { $manual_config = TRUE; } // load the necessary libraries // migrate to latest database $this->load->library('migration'); $this->migration->latest(); // load everything needed for a normal startup $this->load->library('session'); $this->load->library('tank_auth'); $this->load->library('datamapper'); // load the settings from the now filled database load_settings(); $user = $this->tank_auth->create_user($post["username"], $post["email"], $post["password"], FALSE); if ($user !== FALSE) { $profile = new Profile(); $profile->where('user_id', $user['user_id'])->get(); $profile->group_id = 1; $profile->save(); } // create the generic dirs that you can find in content folder if (!is_dir('content/ads')) { mkdir('content/ads'); } if (!is_dir('content/cache')) { mkdir('content/cache'); } if (!is_dir('content/logs')) { mkdir('content/logs'); } if (!is_dir('content/comics')) { mkdir('content/comics'); } // if install can't make that config.php file, tell the user to do it manually if ($manual_config) { $this->notices = array(); $data["config"] = $config; $this->viewdata['main_content_view'] = $this->load->view("install/manual_config", $data, TRUE); $this->load->view("install/default", $this->viewdata); return 'stop'; } // a nice notice to tell that FoOlSlide install was a success flash_notice('notice', _('FoOlSlide has installed successfully. Check the preferences and make sure you create a team for your own chapters.')); redirect('/admin/'); }
public function update_level() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); $data["actions"] = Session::get('actions'); if (in_array('side_nuevo_nivel', $data["actions"])) { // Validate the info, create rules for the inputs $attributes = array('name' => 'Nombre del Nivel'); $messages = array(); $level_id = Input::get('level_id'); $rules = array('name' => 'required|alpha_num_dash|min:2|max:45|unique:levels,name,' . $level_id . ',id,deleted_at,NULL'); // Run the validation rules on the inputs from the form $validator = Validator::make(Input::all(), $rules, $messages, $attributes); // If the validator fails, redirect back to the form //$convocatoria_id = Input::get('convocatoria_id'); $url = "levels/edit_level" . "/" . $level_id; if ($validator->fails()) { return Redirect::to($url)->withErrors($validator)->withInput(Input::all()); } else { $teacher_id = Input::get('teacher_id'); $level = Level::find($level_id); $level->name = Input::get('name'); if ($teacher_id && $teacher_id != $level->teacher_id) { $teacher = Teacher::find($teacher_id); // verificar si el profesor ya es tutor de otro nivel if ($teacher->level) { Session::flash('error', 'El profesor ya es Profesor de Aula o Tutor de otro nivel.'); return Redirect::to($url)->withInput(Input::all()); } // desasignar el perfil de tutor al profesor anterior $previus_teacher = $level->teacher; if ($previus_teacher) { $previus_teacher->user->profiles()->detach(Profile::where('name', '=', 'Tutor')->first()->id); } // asignar el perfil de tutor al profesor $user = $teacher->user; $user->profiles()->attach(Profile::where('name', '=', 'Tutor')->first()->id); $level->teacher_id = $teacher_id; } $level->save(); Session::flash('message', 'Se editó correctamente el Nivel.'); // Llamo a la función para registrar el log de auditoria $log_description = "Se editó el Nivel con id {{$level->id}}"; Helpers::registerLog(4, $log_description); return Redirect::to($url); } } else { // Llamo a la función para registrar el log de auditoria $descripcion_log = "Se intentó acceder a la ruta '" . Request::path() . "' por el método '" . Request::method() . "'"; Helpers::registrarLog(10, $descripcion_log); Session::flash('error', 'Usted no tiene permisos para realizar dicha acción.'); return Redirect::to('/dashboard'); } } else { return View::make('error/error'); } }