我会尽可能地清楚地说明这一点。
我推出了一个make Auth调用,以便使用laravel的登录和注册功能,之后只使用模板来提供我想要的需求。
如果用户是管理员,他/她可以注册新用户。
public function openNewUser(){
return view('auth.register');
}
NB。部分更新。
public function registerNewUser(Request $request){
$this->validate($request,[
'email' => 'required|email|unique:users',
'name' => 'required|max:120',
'password' => 'required|min:4|confirmed']);
$user = new User();
$user->name = $request->name;
$user->email = $request->email;
$user->password = encrypt($request->password);
if (Gate::denies('register-user')) {
return redirect()->back();
}
$user->save();
return view('home');
}
public function userUpdate(Request $ request,$ user_id){
$this->validate($request,[
'email' => 'required|email',
'name' => 'required|max:120',
'password' => 'required|min:4|confirmed']);
$user = new User();
$user->name = $request->name;
$user->email = $request->email;
$user->password = encrypt($request->password);
if (Gate::allows('register-user')) {
$user->save();
$user->roles()->attach($request->roles);
return redirect()->route('view_users');
}elseif (Gate::denies('register-user')) {
if (Auth::id() == $user_id) {
$user->save();
$user->roles()->attach($request->roles);
return redirect()->route('view_users');
}else{
return redirect()->back();
}
}
}
问题2.我刚刚意识到我正在使用我的新注册进行的所有登录都提供这些凭据与我们的记录不匹配。即使凭据存在并且已正确注册。 我正在使用laravel提供的登录信息,但我创建了自己的注册。
请如何编辑和更新我的用户,以及注册后能够登录
答案 0 :(得分:1)
// Profile Update author
public function UpdateProfile(Request $request)
{
$this->validate($request,[
'name' => 'required',
'email' => 'required|email',
'image' => 'mimes:jpeg,jpg,bmp,png',
]);
$image = $request->file('image');
$slug = str_slug($request->name);
$user = User::findOrFail(Auth::id());
if($request->hasfile('image'))
{
$image=$request->file('image');
$currentDate = Carbon::now()->toDateString();
$imageName = $slug.'-'.$currentDate.'-'. uniqid() .'.'. $image->getClientOriginalExtension();
$image_resize = Image::make($image->getRealPath());
$image_resize->resize(500,400);
unlink('storage/uploads/author/profile/'.$user->image);
$image_resize->save('storage/uploads/author/profile/'.$imageName);
} else {
$imageName = $user->image;
}
$user->name = $request->name;
$user->email = $request->email;
$user->image = $imageName;
$user->about = $request->about;
$user->save();
Toastr::success('Profile Successfully Updated :)','Success');
return redirect()->back();
}
//Password Update
public function passwordUpdate(Request $request)
{
$this->validate($request,[
'old_password' => 'required',
'password' => 'required|confirmed',
]);
$hashedPassword = Auth::user()->password;
if (Hash::check($request->old_password,$hashedPassword))
{
if (!Hash::check($request->password,$hashedPassword))
{
$user = User::find(Auth::id());
$user->password = Hash::make($request->password);
$user->save();
Toastr::success('Password Successfully Changed','Success');
Auth::logout();
return redirect()->back();
} else {
Toastr::error('New password cannot be the same as old password.','Error');
return redirect()->back();
}
} else {
Toastr::error('Current password not match.','Error');
return redirect()->back();
}
}
答案 1 :(得分:0)
您使用的是什么版本的Laravel?
以下是register()
中的{v5.3} RegisterController.php
方法,至少部分用于注册:
public function register(Request $request)
{
...
// save and login user
$user = $this->create($request->all());
$this->guard()->login($user);
...
}
...
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'lastname' => $data['lastname'],
'phone' => $data['phone'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
以及login()
LoginController.php
方法
public function login(Request $request)
{
$credentials = $this->credentials($request);
...
if ($this->guard()->attempt($credentials, $request->has('remember'))) {
return $this->sendLoginResponse($request);
}
}
希望我没有错过任何东西。 请记住,5.2版本已经发生了变化。
答案 2 :(得分:0)
我发现了什么问题,因为我使用Laravel的登录,我的注册必须使用bycrypt进行加密,这是Laravel注册使用的,但我在创建自己的注册时使用加密,所以当发生冲突时登录。(Remembere我使用Laravels登录而不是我自己写的登录)。我希望这有助于某人