/** * Setup the test environment. * * @return void */ public function setUp() { parent::setUp(); $this->signInWithManager(); $this->propertyId = $this->getTestPropertyId(true); $this->userId = User::where('username', 'test')->first()->getAttribute('id'); }
/** * Run the database seeds. * * @return void */ public function run() { if (app()->environment(['local', 'testing'])) { foreach (['test' => 'student', 'testLab' => 'lab', 'testManager' => 'manager'] as $key => $value) { if (!User::where('username', $key)->exists()) { factory(User::class)->create(['username' => $key, 'password' => bcrypt('test')])->roles()->save(Role::where('name', $value)->first()); } } } }
/** * Login with the provided username & password in local first, if * failed, try login in center. * * @param Request * @return Json */ public function login(Request $request) { $username = $request->input('username'); $password = $request->input('password'); // if login failed if (!Auth::attempt(['username' => $username, 'password' => $password]) && self::loginCheckSSO($username, $password) === 'SUCCESS') { $user = User::where('username', '=', $username)->first(); Auth::login($user); } $response = ['is_student' => \Entrust::hasRole('student'), 'is_manager' => \Entrust::hasRole('manager'), 'status' => Auth::check()]; return response()->json($response); }
/** * Display a listing of the others borrow. * * @param Request $request * @return \Illuminate\Http\Response */ public function login($account, $passwd) { if (login_check_sso($account, $passwd) == 'SUCCESS') { $user = User::where('username', '=', $account)->find(); if ($user == null) { //add this user to database; //User::create(); //Role::Add...; $user = User::where('username', '=', $account)->find(); } Auth::loginUsingId($user->id); } else { //Manager $user = User::where('username', '=', $account)->where('password', '=', $passwd)->find(); if ($user != null) { Auth::loginUsingId($user->id); } } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $affect_row = User::where('id', '=', $id)->update(['role' => $request->input('role'), 'username' => $request->input('username'), 'password' => $request->input('password'), 'nickname' => $request->input('nickname'), 'email' => $request->input('email'), 'phone' => $request->input('phone'), 'group' => $request->input('group')]); return response()->json(['status' => $affect_row == 1 ? 0 : 2]); }
/** * 以一般使用者身份登入. * * @param string $username */ public function signIn($username = '******') { $this->actingAs(User::where('username', $username)->first()); }
/** * Store a newly created other property borrow in storage. * * @param Request $request * @return Json */ public function store(Request $request) { $user = User::where('username', '=', $request->input('username'))->first(); if ($user === null) { return response()->json(['status' => 2]); } // Borrow out other property, no check for user should borrow property by going to the office personally. Loan::create(array_merge(array_only($request->all(), ['property_id', 'date_began_at', 'date_ended_at', 'remark']), ['user_id' => $user->id, 'type' => Category::getCategoryId('loan.type', $request->input('type', 'others')), 'status' => Category::getCategoryId('loan.status', 'accepted')])); return response()->json(['status' => 0]); }
/** @test */ public function create_loan_2() { $this->call('POST', '/other-create', ['property_id' => $this->getTestPropertyId(), 'date_began_at' => '2016-03-02', 'date_ended_at' => '2016-03-07', 'user_id' => User::where('username', 'test')->first()->getAttribute('id'), 'type' => $this->randomCategoryName('loan.type')]); $this->assertResponseCreated(); $this->seeJson(); }