1
0
Fork 0
pixelfed/app/Http/Controllers/SettingsController.php

132 lines
2.8 KiB
PHP
Raw Normal View History

2018-05-26 22:53:21 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\{Profile, User};
use Auth;
class SettingsController extends Controller
{
public function __construct()
{
return $this->middleware('auth');
}
public function home()
{
return view('settings.home');
}
public function homeUpdate(Request $request)
{
$this->validate($request, [
'name' => 'required|string|max:30',
'bio' => 'nullable|string|max:125'
2018-05-26 22:53:21 +00:00
]);
2018-06-01 03:11:56 +00:00
$changes = false;
2018-05-26 22:53:21 +00:00
$name = $request->input('name');
2018-06-01 03:11:56 +00:00
$bio = $request->input('bio');
2018-05-26 22:53:21 +00:00
$user = Auth::user();
$profile = $user->profile;
if($profile->name != $name) {
2018-06-01 03:11:56 +00:00
$changes = true;
2018-05-26 22:53:21 +00:00
$user->name = $name;
$profile->name = $name;
2018-06-01 03:11:56 +00:00
}
if($profile->bio != $bio) {
$changes = true;
$profile->bio = $bio;
}
2018-05-26 22:53:21 +00:00
2018-06-01 03:11:56 +00:00
if($changes === true) {
$user->save();
$profile->save();
2018-05-26 22:53:21 +00:00
return redirect('/settings/home')->with('status', 'Profile successfully updated!');
}
2018-06-01 03:11:56 +00:00
2018-05-26 22:53:21 +00:00
return redirect('/settings/home');
}
public function password()
{
return view('settings.password');
}
2018-06-01 03:11:56 +00:00
public function passwordUpdate(Request $request)
{
$this->validate($request, [
'current' => 'required|string',
'password' => 'required|string',
'password_confirmation' => 'required|string',
]);
$current = $request->input('current');
$new = $request->input('password');
$confirm = $request->input('password_confirmation');
$user = Auth::user();
if(password_verify($current, $user->password) && $new === $confirm) {
$user->password = bcrypt($new);
$user->save();
return redirect('/settings/home')->with('status', 'Password successfully updated!');
}
return redirect('/settings/home')->with('error', 'There was an error with your request!');
}
2018-05-26 22:53:21 +00:00
public function email()
{
return view('settings.email');
}
public function avatar()
{
return view('settings.avatar');
}
public function notifications()
{
return view('settings.notifications');
}
public function privacy()
{
return view('settings.privacy');
}
public function security()
{
return view('settings.security');
}
public function applications()
{
return view('settings.applications');
}
public function dataExport()
{
return view('settings.dataexport');
}
public function dataImport()
{
return view('settings.import.home');
}
public function dataImportInstagram()
{
return view('settings.import.ig');
}
public function developers()
{
return view('settings.developers');
}
}