예제 #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('UlibierPermission')->delete();
     DB::table('Ulibier')->delete();
     DB::table('UlibierProfile')->delete();
     \App\UlibierPermission::create(array('permission_name' => 'admin'));
     \App\UlibierPermission::create(array('permission_name' => 'user'));
     $csv = new CSV();
     $ulibiers = $csv->fromFile(dirname(__FILE__) . '/csv/Ulibier.csv')->toArray();
     $profiles = $csv->fromFile(dirname(__FILE__) . '/csv/UlibierProfile.csv')->toArray();
     for ($i = 0; $i < count($ulibiers); $i++) {
         $k = $ulibiers[$i];
         $v = $profiles[$i];
         $ulibier = new Ulibier();
         $ulibier->fill($k)->setAttribute('password', bcrypt($k['password']))->save();
         $ulibier->profile()->create($v);
     }
 }
예제 #2
0
 /**
  * @param Request $request
  * @return Response
  */
 public function getTrending(Request $request)
 {
     $top = $request->input('top', 3);
     $context = $request->input('context', 'article');
     $data = Ulibier::all()->take($top);
     if ($context === 'article') {
         return $this->getTrendingWithArticle($data);
     }
 }
예제 #3
0
 public function postSignup(Request $request)
 {
     $credentials = $request->only('username', 'password');
     try {
         $user = Ulibier::create($credentials);
     } catch (Exception $e) {
         return response()->json(['error' => 'User already exists.'], 409);
     }
     $token = JWTAuth::fromUser($user);
     return response()->json(compact('token'));
 }
예제 #4
0
 public function getAuthorAvatarAttribute()
 {
     $author = Ulibier::find($this->username);
     return $author->thumbnail_400;
 }
예제 #5
0
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    // get top articles (3)
    $articles = \App\Models\Article::renderAll(3);
    // get top places (6)
    $destinations = \App\Models\Destination::all()->random(6);
    // get top ulibiers (4)
    $users = \App\Ulibier::all();
    return View::make('index', ['articles' => $articles, 'dest' => $destinations, 'users' => $users]);
});
Route::get('/register', function () {
    return View::make('pages.register');
});
Route::get('/profile', function () {
    return View::make('pages.profile');
});
Route::get('/map', function () {
    return View::make('pages.map');
});
Route::get('/test/email', function () {
    return View::make('emails.confirmation');
});
Route::model('destination', \App\Models\Destination::class);
예제 #6
0
 /**
  * Redirect to Facebook/Google OAuth login authentication
  * Kiểm tra xem Email gắn liền với tài khoản mạng xã hội đã được đăng ký
  *  trong CSDL của Ulibi hay chưa
  * Nếu chưa, redirect tới trang đăng ký Ulibier (yêu cầu sử dụng username, điền sắn
  *  một số field đã có sẵn như email, avatar, ...)
  * Nếu đã có, redirect tới postLogin luôn
  * @param string $provider
  * @return Response
  */
 public function socialAuthCallback($provider)
 {
     /** @var \Laravel\Socialite\AbstractUser $p */
     $p = Socialite::with($provider);
     switch ($provider) {
         case 'facebook':
             $p->fields($this->facebookRequiredScopes());
             break;
     }
     if ($user = Socialite::with($provider)->user()) {
         /** @var \App\Ulibier $dbUser */
         $dbUser = Ulibier::whereEmail($user->email)->first();
         if ($dbUser === null) {
             $dbUser = UlibierPermission::getUsers()->members()->create(['username' => $user->id, 'firstname' => $this->getSocialField($provider, $user, 'firstName'), 'lastname' => $this->getSocialField($provider, $user, 'lastName'), 'email' => $this->getSocialField($provider, $user, 'email'), 'password' => bcrypt('123456'), 'registered_with_social_account' => true]);
             $dbUser->profile()->create(['sex' => $this->getSocialField($provider, $user, 'gender'), 'birthday' => new DateTime($this->getSocialField($provider, $user, 'birthday')), 'phonenumber' => '+841667578431']);
             $dbUser->avatar_url = $this->getSocialField($provider, $user, 'avatar');
         }
         return \View::make('pages.auth.redirect', ['form' => ['method' => 'POST', 'action' => '/ulibier/login', 'fields' => ['email' => $dbUser->email, 'via' => $provider]]]);
     } else {
         return 'something went wrong';
     }
 }