public function login(Request $request) { // dd(\Crypt::encrypt('*****@*****.**')); try { $email = \Crypt::decrypt($request->get('token')); } catch (\Exception $e) { return abort('403', 'Forbidden'); } $user = User::whereEmail($email)->first(); if (!$user) { return abort('403', 'Forbidden'); } if (!$user->account) { $b2bCompany = \DB::connection('mysql-b2b')->table('companies')->where('user_id', '=', $user->id)->first(); // $b2bCompany = false; $accountName = $b2bCompany ? $b2bCompany->company_name : $user->email; $account = new Account(); $account->ip = $request->getClientIp(); $account->name = $accountName; $account->account_key = str_random(RANDOM_KEY_LENGTH); $account->save(); $user->account_id = $account->id; $user->registered = true; $user->save(); $exists = \DB::connection('mysql')->table('users')->whereId($user->id)->count(); if (!$exists) { \DB::connection('mysql')->table('users')->insert(['id' => $user->id, 'account_id' => $user->account_id, 'created_at' => $user->created_at, 'updated_at' => $user->updated_at, 'deleted_at' => $user->deleted_at, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'phone' => $user->phone, 'username' => $user->username, 'email' => $user->email, 'password' => $user->password, 'confirmation_code' => $user->confirmation_code, 'registered' => $user->registered, 'confirmed' => $user->confirmed, 'notify_sent' => $user->notify_sent, 'notify_viewed' => $user->notify_viewed, 'notify_paid' => $user->notify_paid, 'public_id' => $user->public_id, 'force_pdfjs' => false, 'remember_token' => $user->remember_token, 'news_feed_id' => $user->news_feed_id, 'notify_approved' => $user->notify_approved, 'failed_logins' => $user->failed_logins, 'dark_mode' => $user->dark_mode, 'referral_code' => $user->referral_code]); } } \Auth::loginUsingId($user->id); return redirect('/'); }
public function run() { $users = User::all(); foreach ($users as $user) { foreach ($this->accounts as $account) { $tmp = new Account(['name' => $account]); $tmp->user()->associate($user); $tmp->save(); } } }
/** * @test * @return void */ public function it_can_delete_an_account() { $this->logInUser(); $name = 'echidna'; $account = new Account(compact('name')); $account->user()->associate($this->user); $account->save(); $response = $this->call('DELETE', '/api/accounts/' . $account->id); $this->assertEquals(204, $response->getStatusCode()); $response = $this->call('DELETE', '/api/account/' . $account->id); $this->assertEquals(404, $response->getStatusCode()); }
/** * Execute the console command. * * @return mixed */ public function handle() { $accountModel = new Account(); $accounts = $accountModel->get(); $this->output->progressStart($accounts->count()); foreach ($accounts as $account) { $this->call('sync:groups', array('account_id' => $account->id)); $this->output->progressAdvance(); } $this->output->progressFinish(); $this->info("\n同步完成。"); }
/** * DELETE /api/accounts/{accounts} * @param DeleteAccountRequest $deleteAccountRequest * @param Account $account * @return Response */ public function destroy(DeleteAccountRequest $deleteAccountRequest, Account $account) { try { $account->delete(); return response([], Response::HTTP_NO_CONTENT); } catch (\Exception $e) { //Integrity constraint violation if ($e->getCode() === '23000') { $message = 'Account could not be deleted. It is in use.'; } else { $message = 'There was an error'; } return response(['error' => $message, 'status' => Response::HTTP_BAD_REQUEST], Response::HTTP_BAD_REQUEST); } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { // gte the requested subdomain $subdomain = getSubdomainFromHttpHost(); // check that the account exists. if ($this->account->exists($subdomain)) { // add the account's subdomain to the request $request->account = $subdomain; // contimue on return $next($request); } else { // if it dosn't throw 404 error throw new HttpNotFoundException(); } }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = Account::findByUsername($this->username); } return $this->_user; }
public function fire() { $this->info(date('Y-m-d') . ' ChargeRenewalInvoices...'); $ninjaAccount = $this->accountRepo->getNinjaAccount(); $invoices = Invoice::whereAccountId($ninjaAccount->id)->whereDueDate(date('Y-m-d'))->where('balance', '>', 0)->with('client')->orderBy('id')->get(); $this->info(count($invoices) . ' invoices found'); foreach ($invoices as $invoice) { // check if account has switched to free since the invoice was created $account = Account::find($invoice->client->public_id); if (!$account) { continue; } $company = $account->company; if (!$company->plan || $company->plan == PLAN_FREE) { continue; } try { $this->info("Charging invoice {$invoice->invoice_number}"); $this->paymentService->autoBillInvoice($invoice); } catch (Exception $exception) { $this->info('Error: ' . $exception->getMessage()); } } $this->info('Done'); }
public function fire() { $this->info(date('Y-m-d') . ' Running SendRenewalInvoices...'); $today = new DateTime(); $sentTo = []; // get all accounts with pro plans expiring in 10 days $accounts = Account::whereRaw('datediff(curdate(), pro_plan_paid) = 355')->orderBy('id')->get(); $this->info(count($accounts) . ' accounts found'); foreach ($accounts as $account) { // don't send multiple invoices to multi-company users if ($userAccountId = $this->accountRepo->getUserAccountId($account)) { if (isset($sentTo[$userAccountId])) { continue; } else { $sentTo[$userAccountId] = true; } } $client = $this->accountRepo->getNinjaClient($account); $invitation = $this->accountRepo->createNinjaInvoice($client); // set the due date to 10 days from now $invoice = $invitation->invoice; $invoice->due_date = date('Y-m-d', strtotime('+ 10 days')); $invoice->save(); $this->mailer->sendInvoice($invoice); $this->info("Sent invoice to {$client->getDisplayName()}"); } $this->info('Done'); }
/** * UPDATE /api/favouritesTransactions/{favouriteTransactions} * @param Request $request * @param FavouriteTransaction $favourite * @return Response */ public function update(Request $request, FavouriteTransaction $favourite) { // Create an array with the new fields merged $data = array_compare($favourite->toArray(), $request->only(['name', 'type', 'description', 'merchant', 'total'])); $favourite->update($data); if ($request->has('account_id')) { $favourite->account()->associate(Account::findOrFail($request->get('account_id'))); $favourite->fromAccount()->dissociate(); $favourite->toAccount()->dissociate(); $favourite->save(); } if ($request->has('from_account_id')) { $favourite->fromAccount()->associate(Account::findOrFail($request->get('from_account_id'))); $favourite->account()->dissociate(); $favourite->save(); } if ($request->has('to_account_id')) { $favourite->toAccount()->associate(Account::findOrFail($request->get('to_account_id'))); $favourite->account()->dissociate(); $favourite->save(); } if ($request->has('budget_ids')) { $favourite->budgets()->sync($request->get('budget_ids')); } $favourite = $this->transform($this->createItem($favourite, new FavouriteTransactionTransformer()))['data']; return response($favourite, Response::HTTP_OK); }
public function run() { $this->command->info('Running UserTableSeeder'); Eloquent::unguard(); $account = Account::create(['name' => 'Test Account', 'account_key' => str_random(16), 'timezone_id' => 1]); User::create(['email' => TEST_USERNAME, 'username' => TEST_USERNAME, 'account_id' => $account->id, 'password' => Hash::make(TEST_PASSWORD)]); }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = Account::findOne(['email' => $this->username]); } return $this->_user; }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('events')->insert([['id' => '1', 'eventName' => 'PartyNight', 'date' => '2016-01-01', 'startTime' => '14:00:00', 'endTime' => '15:00:00', 'location' => 'Beijing', 'description' => 'A test Event 1.', 'capacity' => 123, 'conferenceID' => 1], ['id' => '2', 'eventName' => 'Speech', 'date' => '2017-01-01', 'startTime' => '12:00:00', 'endTime' => '12:30:00', 'location' => 'Mumbai', 'description' => 'A test Event 2.', 'capacity' => 123, 'conferenceID' => 1]]); $role = RoleCreate::AllEventRoles(1); Account::where('email', 'root@localhost')->get()->first()->attachRole($role); $role = RoleCreate::AllEventRoles(2); Account::where('email', 'root@localhost')->get()->first()->attachRole($role); }
public function run() { $this->command->info('Running UserTableSeeder'); Eloquent::unguard(); $account = Account::create(['name' => 'Test Account', 'account_key' => str_random(16), 'timezone_id' => 1]); User::create(['email' => TEST_USERNAME, 'username' => TEST_USERNAME, 'account_id' => $account->id, 'password' => Hash::make(TEST_PASSWORD), 'registered' => true, 'confirmed' => true]); Affiliate::create(['affiliate_key' => SELF_HOST_AFFILIATE_KEY]); }
public function showSetup() { if (Utils::isNinja() || Utils::isDatabaseSetup() && Account::count() > 0) { return Redirect::to('/'); } $view = View::make('setup'); return Response::make($view); }
public static function isWhiteLabel() { if (Utils::isNinjaProd()) { return false; } $account = \App\Models\Account::first(); return $account && $account->hasFeature(FEATURE_WHITE_LABEL); }
public function actionDelete($id) { Account::findOne($id)->delete(); $session = new Session(); $session->open(); $session->setFlash('message', 'Deleted.'); return $this->redirect(['index']); }
public function validateCredentials(UserContract $user, array $credentials) { $profile = $user instanceof Account ? $user : Account::find($user->getAuthIdentifier()); if ($profile && $profile->id == $user->getAuthIdentifier()) { return static::PAMAuthenticate($profile->username, $credentials['password']); } return false; }
/** * Run the database seeds. * * @return void */ public function run() { $conferences = [['id' => 1, 'conferenceName' => 'Foo', 'dateStart' => '2016-01-01', 'dateEnd' => '2016-02-01', 'location' => 'Earth', 'description' => 'A test conference.', 'hasTransportation' => true, 'hasAccommodations' => false], ['id' => 2, 'conferenceName' => 'Bar', 'dateStart' => '2016-02-03', 'dateEnd' => '2016-02-05', 'location' => 'Earth', 'description' => 'A test conference number 2.', 'hasTransportation' => true, 'hasAccommodations' => true]]; foreach ($conferences as $conf) { $c = Conference::create($conf); $role = RoleCreate::AllConferenceRoles($c->id); Account::where('email', 'root@localhost')->get()->first()->attachRole($role); } }
public function updateProPlanPaid($clientPublicId, $proPlanPaid) { $account = Account::whereId($clientPublicId)->first(); if (!$account) { return; } $account->pro_plan_paid = $proPlanPaid; $account->save(); }
/** * @test * @return void */ public function it_can_update_an_existing_account() { $this->logInUser(); $account = Account::forCurrentUser()->first(); $response = $this->call('PUT', '/api/accounts/' . $account->id, ['name' => 'numbat']); $content = json_decode($response->getContent(), true); $this->checkAccountKeysExist($content); $this->assertEquals('numbat', $content['name']); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); }
/** * @test * @return void */ public function it_displays_an_account() { $this->logInUser(); $account = Account::forCurrentUser()->first(); $response = $this->call('GET', '/api/accounts/' . $account->id); $content = json_decode($response->getContent(), true); $this->checkAccountKeysExist($content); // $this->assertEquals($this->user->id, $content['user_id']); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); }
public function run() { $this->command->info('Running UserTableSeeder'); Eloquent::unguard(); $faker = Faker\Factory::create(); $company = Company::create(); $account = Account::create(['name' => $faker->name, 'address1' => $faker->streetAddress, 'address2' => $faker->secondaryAddress, 'city' => $faker->city, 'state' => $faker->state, 'postal_code' => $faker->postcode, 'country_id' => Country::all()->random()->id, 'account_key' => str_random(RANDOM_KEY_LENGTH), 'invoice_terms' => $faker->text($faker->numberBetween(50, 300)), 'work_phone' => $faker->phoneNumber, 'work_email' => $faker->safeEmail, 'invoice_design_id' => min(InvoiceDesign::all()->random()->id, 10), 'header_font_id' => min(Font::all()->random()->id, 17), 'body_font_id' => min(Font::all()->random()->id, 17), 'primary_color' => $faker->hexcolor, 'timezone_id' => 1, 'company_id' => $company->id]); User::create(['email' => TEST_USERNAME, 'username' => TEST_USERNAME, 'account_id' => $account->id, 'password' => Hash::make(TEST_PASSWORD), 'registered' => true, 'confirmed' => true, 'notify_sent' => false, 'notify_paid' => false]); Affiliate::create(['affiliate_key' => SELF_HOST_AFFILIATE_KEY]); }
/** * Bootstrap the application services. */ public function boot() { User::observe('App\\Observers\\UserObserver'); Reply::observe('App\\Observers\\ReplyObserver'); Event::observe('App\\Observers\\EventObserver'); Material::observe('App\\Observers\\MaterialObserver'); Account::observe('App\\Observers\\AccountObserver'); FanGroup::observe('App\\Observers\\FanGroupObserver'); Fan::observe('App\\Observers\\FanObserver'); }
public function showIndex() { Session::reflash(); if (!Utils::isNinja() && (!Utils::isDatabaseSetup() || Account::count() == 0)) { return Redirect::to('/setup'); } elseif (Auth::check()) { return Redirect::to('/dashboard'); } else { return Redirect::to('/login'); } }
public function actionIndex() { $user = Yii::$app->user; $month_plan = Plan::getMonthPlan($user->id); $month_account_all = Account::getMonthAccountAll($user->id); $week_account_all = Account::getWeekAccountAll($user->id); $month_balance = $month_plan - $month_account_all; $month_account_income_all = Account::getMonthAccountIncomeAll($user->id); $month_account_list = Account::getMonthAccountList($user->id); return $this->render('index', ['month_plan' => $month_plan, 'month_account_all' => $month_account_all, 'month_balance' => $month_balance, 'month_account_income_all' => $month_account_income_all, 'month_account_list' => $month_account_list]); }
public function resetPassword(Request $request) { if (!$request->has('email')) { return response()->json(['message' => 'no_email_given'], 400); } $account = Account::where('email', $request->input('email'))->get()->first(); if (!isset($account)) { return response()->json(['message' => 'account_not_found'], 400); } $this->dispatch(new ResetPassword($account)); return ["message" => "email_pending"]; }
private function truncate() { User::truncate(); Savings::truncate(); Budget::truncate(); Account::truncate(); Transaction::truncate(); FavouriteTransaction::truncate(); SavedFilter::truncate(); DB::table('budgets_favourite_transactions')->truncate(); DB::table('budgets_transactions')->truncate(); }
/** For each account create an item. If previous balance sheet exists and has value - set it as default, otherwise - set to zero */ public function initAmounts() { $accounts = Account::find()->orderBy('order_code')->all(); $prevBalance = $this->getPreviouBalance(); for ($i = 0; $i < count($accounts); $i++) { $amount = new BalanceAmount(); $amount->account_id = $accounts[$i]->id; $amount->balance_sheet_id = $this->id; $amount->amount = $prevBalance ? $prevBalance->balanceAmounts[$i]->amount : 0; $amount->save(); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Account::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['account_id' => $this->account_id, 'person_id' => $this->person_id, 'remain_time' => $this->remain_time]); return $dataProvider; }