本文整理汇总了PHP中auth函数的典型用法代码示例。如果您正苦于以下问题:PHP auth函数的具体用法?PHP auth怎么用?PHP auth使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了auth函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticated
/**
* Overrides the action when a user is authenticated.
* If the user authenticated but does not exist in the user table we create them.
* @param Request $request
* @param Authenticatable $user
* @return \Illuminate\Http\RedirectResponse
* @throws AuthException
*/
protected function authenticated(Request $request, Authenticatable $user)
{
// Explicitly log them out for now if they do no exist.
if (!$user->exists) {
auth()->logout($user);
}
if (!$user->exists && $user->email === null && !$request->has('email')) {
$request->flash();
session()->flash('request-email', true);
return redirect('/login');
}
if (!$user->exists && $user->email === null && $request->has('email')) {
$user->email = $request->get('email');
}
if (!$user->exists) {
// Check for users with same email already
$alreadyUser = $user->newQuery()->where('email', '=', $user->email)->count() > 0;
if ($alreadyUser) {
throw new AuthException('A user with the email ' . $user->email . ' already exists but with different credentials.');
}
$user->save();
$this->userRepo->attachDefaultRole($user);
auth()->login($user);
}
$path = session()->pull('url.intended', '/');
$path = baseUrl($path, true);
return redirect($path);
}
示例2: confirmEmail
/**
* @param $token
*
* @return \Illuminate\Http\RedirectResponse
*/
public function confirmEmail($token)
{
$user = User::whereActivationToken($token)->firstOrFail();
$user->confirmEmail();
auth()->login($user);
return redirect()->intended()->with('success', 'Email verified!');
}
示例3: destroy
/**
* Removes the specified user from the specified role.
*
* @param int|string $roleId
* @param int|string $userId
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy($roleId, $userId)
{
$this->authorize('admin.roles.users.destroy');
$role = $this->role->findOrFail($roleId);
$user = $role->users()->findOrFail($userId);
// Retrieve the administrators name.
$adminName = Role::getAdministratorName();
// Retrieve all administrators.
$administrators = $this->user->whereHas('roles', function ($query) use($adminName) {
$query->whereName($adminName);
})->get();
$admin = Role::whereName($adminName)->first();
// We need to verify that if the user is trying to remove all roles on themselves,
// and they are the only administrator, that we throw an exception notifying them
// that they can't do that. Though we want to allow the user to remove the
// administrator role if more than one administrator exists.
if ($user->hasRole($admin) && $user->id === auth()->user()->id && count($administrators) === 1) {
flash()->setTimer(null)->error('Error!', "Unable to remove the administrator role from this user. You're the only administrator.");
return redirect()->route('admin.roles.show', [$roleId]);
}
if ($role->users()->detach($user)) {
flash()->success('Success!', 'Successfully removed user.');
return redirect()->route('admin.roles.show', [$roleId]);
}
flash()->error('Error!', 'There was an issue removing this user. Please try again.');
return redirect()->route('admin.roles.show', [$roleId]);
}
示例4: __construct
public function __construct($criteria)
{
$this->scope['businessesIds'] = auth()->user()->businesses->transform(function ($item) {
return $item->id;
});
$this->criteria = $criteria;
}
示例5: postStart
/**
* Show course details
*
* @return Response
*/
public function postStart(Course\Course $course)
{
$section = $course->sections()->first();
auth()->user()->courses()->attach($course);
auth()->user()->sections()->attach($section);
return redirect()->route('front.section', [$course, $section, $section->slug()]);
}
示例6: authenticatePusher
/**
* Generate Pusher authentication token for currently logged user.
*
* @param Request $request
* @param PusherManager $pusher
*
* @return string
*/
public function authenticatePusher(Request $request, PusherManager $pusher)
{
$channelName = 'private-u-' . auth()->id();
$socketId = $request->input('socket_id');
$pusher->connection();
return $pusher->socket_auth($channelName, $socketId);
}
示例7: saveEntry
public function saveEntry(Request $request)
{
$id = hashids_decode($request->get('content'));
$entry = Entry::findOrFail($id);
$entry->saves()->create(['user_id' => auth()->id()]);
return Response::json(['status' => 'ok']);
}
示例8: authorize
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
if (auth()->guest()) {
return false;
}
return true;
}
示例9: index
public function index()
{
if (auth()->check()) {
return view('dashboard.index')->withLeftNavigation('dashboard');
}
return view('auth.login');
}
示例10: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (auth()->check() && auth()->user()->role == 1) {
return $next($request);
}
return redirect('/home');
}
示例11: getFavoriteList
public function getFavoriteList()
{
$authId = auth()->user()->id;
$favoritecandidatelist = \App\FavoriteCandidate::where('user_id', $authId)->get();
$favoritepartylist = \App\FavoriteParty::where('user_id', $authId)->get();
return view('user.favorites', compact('favoritecandidatelist', 'favoritepartylist'));
}
示例12: build_workspace_menu
function build_workspace_menu($menuarray = array())
{
global $base, $baseURL;
foreach ($menuarray as $plmenu) {
if ($plmenu) {
foreach ($plmenu as $menuitem) {
// Use a default image if we cant find the one specified.
if (!file_exists($base . $menuitem['image']) or !$menuitem['image']) {
$menuitem['image'] = '/images/silk/plugin.png';
}
if (!$menuitem['tooltip']) {
$menuitem['tooltip'] = $menuitem['menutitle'];
}
// Check the authorization and print the menuitem if the are authorized
if (auth($menuitem['authname'], 3) || !$menuitem['authname']) {
$wsmenuhtml .= <<<EOL
<div class="row"
onMouseOver="this.className='hovered';"
onMouseOut="this.className='row';"
onClick="ona_menu_closedown(); {$menuitem['commandjs']};"
title="{$menuitem['tooltip']}"
><img style="vertical-align: middle;" src="{$baseURL}{$menuitem['image']}" border="0"
/> {$menuitem['menutitle']}</div>
EOL;
}
}
}
}
return $wsmenuhtml;
}
示例13: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$user = auth()->user();
$thread = new Thread($request->all());
$user->threads()->save($thread);
return redirect(route('intern.discuss.threads.show', [$thread->forum->slug, $thread->slug]));
}
示例14: store
public function store(Requests\StorePostRequest $request, $post_id = null)
{
$post = Posts::findOrNew($post_id);
if (empty($post)) {
redirect()->back()->withInput();
}
$seo_title = $request->get('seo_title', '') != '' ? $request->get('seo_title') : $request->get('title');
if ($request->hasFile('img')) {
$filename = $this->_uploadMiniature($request->file('img'));
$post->img = $filename;
}
$post->user_id = auth()->user()->id;
$post->category_id = $request->get('category_id');
$post->title = $request->get('title');
$post->excerpt = $request->get('excerpt');
$post->content = $request->get('content');
$post->seo_title = strip_tags($seo_title);
$post->seo_description = strip_tags($request->get('seo_description'));
$post->seo_keywords = mb_strtolower(strip_tags($request->get('seo_keywords')));
$post->status = $request->get('status');
$post->published_at = $request->get('published_at');
if ($request->has('update_slug')) {
$post->resluggify();
}
$post->save();
$this->_setTags($request->get('tags'), $post->id);
if ($request->has('ping')) {
Pinger::pingAll($post->title, route('view', ['slug' => $post->slug]));
}
Notifications::add('Blog post saved', 'success');
return Redirect::route('root-post-edit', ['post_id' => $post->id]);
}
示例15: save
public static function save($data)
{
$code = (new Parcels())->getNextCode();
$description = $data[0];
event(new ActivityLog(auth()->user()->username . ' created a parcel ' . $description . ' with the code ' . $code . ' successfully via CSV Upload.'));
return auth()->user()->parcels()->create(['weight' => 1, 'town_id' => 1, 'status_id' => 1, 'description' => $description, 'code' => $code, 'destination' => $data[1]]);
}