Update SettingsController

This commit is contained in:
Daniel Supernault 2018-08-12 20:50:49 -06:00
parent 230f935262
commit a2d4b7c1fc
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -3,7 +3,7 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\{AccountLog, Media, Profile, User};
use App\{AccountLog, EmailVerification, Media, Profile, User};
use Auth, DB;
use App\Util\Lexer\PrettyNumber;
@ -31,24 +31,45 @@ class SettingsController extends Controller
{
$this->validate($request, [
'name' => 'required|string|max:30',
'bio' => 'nullable|string|max:125'
'bio' => 'nullable|string|max:125',
'website' => 'nullable|url',
'email' => 'nullable|email'
]);
$changes = false;
$name = $request->input('name');
$bio = $request->input('bio');
$website = $request->input('website');
$email = $request->input('email');
$user = Auth::user();
$profile = $user->profile;
if($profile->name != $name) {
if($user->email != $email) {
$changes = true;
$user->name = $name;
$profile->name = $name;
$user->email = $email;
$user->email_verified_at = null;
// Prevent old verifications from working
EmailVerification::whereUserId($user->id)->delete();
}
if($profile->bio != $bio) {
$changes = true;
$profile->bio = $bio;
// Only allow email to be updated if not yet verified
if(!$changes && $user->email_verified_at) {
if($profile->name != $name) {
$changes = true;
$user->name = $name;
$profile->name = $name;
}
if($profile->website != $website) {
$changes = true;
$profile->website = $website;
}
if($profile->bio != $bio) {
$changes = true;
$profile->bio = $bio;
}
}
if($changes === true) {