- Fix CRM LOGIN + BIRTHDATE
This commit is contained in:
parent
69b315dec4
commit
a7ef782dcb
5 changed files with 119 additions and 42 deletions
|
|
@ -41,32 +41,63 @@ class LoginController extends Controller
|
|||
$cpcConnect->connect();
|
||||
try {
|
||||
// ---- Authentification du user
|
||||
// En attendant la mise à jour de la crm, on envoi un mot de passe bidon (le même qu'a l'inscription)
|
||||
$cpcConnect->authenticateUser ($email, 'MOTDEPASSE');
|
||||
$cpcConnect->authenticateUser($email, $password);
|
||||
} catch (Exception $e) {
|
||||
return back()->withInput($request->except("password"))->withErrors("Email ou mot de passe incorrect.");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return back()->withInput($request->except("password"))->withErrors("La connexion est impossible pour le moment, veuillez réessayer plus tard.");
|
||||
die();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$userLocal->email_verify_token = Str::uuid();
|
||||
$userLocal->save();
|
||||
Mail::to($email)->send(new VerifyEmail($userLocal));
|
||||
return back()->withInput($request->except("password"))->withErrors("Votre compte existe mais votre email n'est pas confirmé, merci de vérifier vos emails.");
|
||||
}
|
||||
|
||||
if (Auth::attempt(["email" => $email, "password" => $password], $remember)) {
|
||||
if ($userLocal->role === 1)
|
||||
return redirect()->route('bo.dashboard');
|
||||
return redirect()->route('home');
|
||||
} else {
|
||||
return back()->withInput($request->except("password"))->withErrors('Les identifiants entrés sont incorrects.');
|
||||
return back()->withInput($request->except( "password"))->withErrors("Votre compte existe mais votre email n'est pas confirmé, merci de vérifier vos emails.");
|
||||
}
|
||||
} else {
|
||||
return back()->withInput($request->except("password"))->withErrors('Les identifiants entrés sont incorrects.');
|
||||
try {
|
||||
$cpcConnect = new CPCConnection(config('crm.CRM_PLATOS_WSDL'), config('crm.WS_SERVCE_LOGIN'), config('crm.WS_SERVCE_PASSWORD'));
|
||||
$cpcConnect->connect();
|
||||
try {
|
||||
// ---- Authentification du user
|
||||
$oCrmUser = $cpcConnect->authenticateUser($email, $password);
|
||||
|
||||
$userLocal = User::create([
|
||||
'crm_id' => $oCrmUser->iId,
|
||||
'civility' => $oCrmUser->zCivilite,
|
||||
'firstname' => $oCrmUser->zPrenom,
|
||||
'lastname' => $oCrmUser->zNom,
|
||||
'birth_date' => $oCrmUser->zDateNaissance,
|
||||
'email' => $oCrmUser->zEmail,
|
||||
'password' => Hash::make("MOTDEPASSE"),
|
||||
'address' => $oCrmUser->zAdresse1,
|
||||
'address2' => $oCrmUser->zAdresse2,
|
||||
'town' => $oCrmUser->zVille,
|
||||
'postal_code' => $oCrmUser->zCodePostal,
|
||||
'country' => "France",
|
||||
'email_verify_token' => Str::uuid(),
|
||||
'email_verified' => 1
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
return back()->withInput($request->except("password"))->withErrors("Email ou mot de passe incorrect.");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return back()->withInput($request->except("password"))->withErrors("La connexion est impossible pour le moment, veuillez réessayer plus tard.");
|
||||
}
|
||||
}
|
||||
|
||||
$tmpPwd = "MOTDEPASSE";
|
||||
if ($userLocal->role === 1)
|
||||
$tmpPwd = $password;
|
||||
|
||||
if (Auth::attempt(["email" => $email, "password" => $tmpPwd], $remember)) {
|
||||
if ($userLocal->role === 1)
|
||||
return redirect()->route('bo.dashboard');
|
||||
return redirect()->route('saisir-code');
|
||||
} else {
|
||||
return back()->withInput($request->except('password'))->withErrors('Les identifiants entrés sont incorrects.');
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -144,10 +175,22 @@ class LoginController extends Controller
|
|||
$user = User::where('password_token', filter_var($request->token, FILTER_SANITIZE_STRING))->first();
|
||||
if (!$user)
|
||||
return back()->withErrors('Le lien de changement de votre mot de passe est incorrect, veuillez réessayer.');
|
||||
|
||||
// TODO : Ajouter controle du contenu du mot de passe
|
||||
$newPassword = $request->password;
|
||||
$user->password = Hash::make($newPassword);
|
||||
$user->password_token = null;
|
||||
$user->save();
|
||||
|
||||
try {
|
||||
$cpcConnect = new CPCConnection(config('crm.CRM_PLATOS_WSDL'), config('crm.WS_SERVCE_LOGIN'), config('crm.WS_SERVCE_PASSWORD'));
|
||||
$cpcConnect->connect();
|
||||
try {
|
||||
$cpcConnect->changePassword($user->crm_id, $newPassword);
|
||||
} catch (Exception $e) {
|
||||
return back()->withErrors("Une erreur est survenue, veuillez réessayer plus tard.");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return back()->withErrors("Une erreur est survenue, veuillez réessayer plus tard.");
|
||||
}
|
||||
|
||||
return redirect()->route('login')->with('success', 'Vous pouvez désormais vous connecter avec votre nouveau mot de passe.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\VerifyEmail;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use App\User;
|
||||
|
|
@ -12,7 +11,6 @@ use CPCUser;
|
|||
use Exception;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
|
@ -21,6 +19,7 @@ class RegisterController extends Controller
|
|||
{
|
||||
use RegistersUsers;
|
||||
|
||||
// TODO : Utilité ??
|
||||
protected $redirectTo = RouteServiceProvider::HOME;
|
||||
|
||||
public function __construct()
|
||||
|
|
@ -34,6 +33,20 @@ class RegisterController extends Controller
|
|||
|
||||
public function register(Request $request) {
|
||||
|
||||
$request->validate([
|
||||
'lastname' => 'required|string|max:255',
|
||||
'firstname' => 'required|string|max:255',
|
||||
'birth_date' => 'required|string|max:10',
|
||||
'email' => 'required|string|email|max:255|unique:users|confirmed',
|
||||
'password' => 'required|string|min:8|confirmed',
|
||||
'address' => 'required|string|max:255',
|
||||
'address2' => 'max:255',
|
||||
'town' => 'required|string|max:255',
|
||||
'postal_code' => 'required|string|max:255',
|
||||
'country' => 'required|string|max:255',
|
||||
'reglement' => 'accepted',
|
||||
]);
|
||||
|
||||
$civility = $request->civility;
|
||||
$lastname = filter_var($request->lastname, FILTER_SANITIZE_STRING);
|
||||
$firstname = filter_var($request->firstname, FILTER_SANITIZE_STRING);
|
||||
|
|
@ -47,19 +60,29 @@ class RegisterController extends Controller
|
|||
$country = filter_var($request->country, FILTER_SANITIZE_STRING);
|
||||
$news = $request->news !== null ? 1 : 0;
|
||||
$tokenMail = Str::uuid();
|
||||
$request->validate([
|
||||
'lastname' => 'required|string|max:255',
|
||||
'firstname' => 'required|string|max:255',
|
||||
'birth_date' => 'required|date|before_or_equal:' . Carbon::now()->subYears(18)->toDateString(),
|
||||
'email' => 'required|string|email|max:255|unique:users|confirmed',
|
||||
'password' => 'required|string|min:8|confirmed',
|
||||
'address' => 'required|string|max:255',
|
||||
'address2' => 'max:255',
|
||||
'town' => 'required|string|max:255',
|
||||
'postal_code' => 'required|string|max:255',
|
||||
'country' => 'required|string|max:255',
|
||||
'reglement' => 'accepted',
|
||||
]);
|
||||
|
||||
$MJ = Carbon::now()->subYears(18);
|
||||
|
||||
if ($this->isSQLDate($birthDate)){
|
||||
$d = Carbon::createFromFormat('Y-m-d', $birthDate);
|
||||
if (!$d->lessThanOrEqualTo($MJ))
|
||||
return back()
|
||||
->withInput($request->except('password'))
|
||||
->withErrors("Vous devez être majeur pour vous inscrire au jeu.");
|
||||
}elseif ($this->isFormDate($birthDate)){
|
||||
$d = Carbon::createFromFormat('d/m/Y', $birthDate);
|
||||
if (!$d->lessThanOrEqualTo($MJ))
|
||||
return back()
|
||||
->withInput($request->except('password'))
|
||||
->withErrors("Vous devez être majeur pour vous inscrire au jeu.");
|
||||
|
||||
$birthDate = $d->toDateString();
|
||||
|
||||
}else{
|
||||
return back()
|
||||
->withInput($request->except('password'))
|
||||
->withErrors("Erreur sur le champs : date de naissance.");
|
||||
}
|
||||
|
||||
$crmId = null;
|
||||
|
||||
|
|
@ -80,8 +103,7 @@ class RegisterController extends Controller
|
|||
$oCrmUser->addField ("pays", FIELDTYPE_TEXT, "", ucfirst($country));
|
||||
$oCrmUser->zLogin = $email;
|
||||
$oCrmUser->zEmail = $email;
|
||||
// En attendant la mise à jour de la crm, on envoi un mot de passe bidon
|
||||
$oCrmUser->zPassword = "MOTDEPASSE";
|
||||
$oCrmUser->zPassword = $password;
|
||||
if($news == 1) $oCrmUser->iInscritNewLetter = $news ;
|
||||
$oCrmUser->iId = $cpcConnect->createUser($oCrmUser, 1);
|
||||
$crmId = $oCrmUser->iId;
|
||||
|
|
@ -104,7 +126,7 @@ class RegisterController extends Controller
|
|||
'lastname' => $lastname,
|
||||
'birth_date' => $birthDate,
|
||||
'email' => $email,
|
||||
'password' => Hash::make($password),
|
||||
'password' => Hash::make("MOTDEPASSE"),
|
||||
'address' => $address,
|
||||
'address2' => $address2,
|
||||
'town' => $town,
|
||||
|
|
@ -117,9 +139,21 @@ class RegisterController extends Controller
|
|||
|
||||
return redirect()->route('login')
|
||||
->with('success', "Pour finaliser votre inscription, merci de cliquer sur le lien qui vient de vous être envoyé par email<br>" .
|
||||
"Informations complémentaires :<br>" .
|
||||
"- Vérifiez vos spams : l'email de confirmation s'y trouve peut-être<br>" .
|
||||
"- Attention : le mail peut parfois mettre quelques minutes à vous parvenir<br>" .
|
||||
"- L'activation de votre compte doit se faire dans les 24 heures qui suivent la demande de création.");
|
||||
"Informations complémentaires :<br>" .
|
||||
"- Vérifiez vos spams : l'email de confirmation s'y trouve peut-être<br>" .
|
||||
"- Attention : le mail peut parfois mettre quelques minutes à vous parvenir<br>" .
|
||||
"- L'activation de votre compte doit se faire dans les 24 heures qui suivent la demande de création.");
|
||||
}
|
||||
|
||||
private function isSQLDate($date){
|
||||
if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $date))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private function isFormDate($date){
|
||||
if (preg_match("/^(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/[0-9]{4}$/", $date))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@ class CreateUsersTable extends Migration
|
|||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('crm_id')->nullable();
|
||||
$table->integer('civility');
|
||||
$table->integer('civility')->nullable();
|
||||
$table->string('firstname');
|
||||
$table->string('lastname');
|
||||
$table->date('birth_date');
|
||||
$table->string('email')->unique();
|
||||
$table->string('password');
|
||||
$table->string('address');
|
||||
$table->string('address')->nullable();
|
||||
$table->string('address2')->nullable();
|
||||
$table->string('town');
|
||||
$table->string('postal_code');
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class CreateSettings extends Migration
|
|||
$table->text('notification_emails')->nullable();
|
||||
$table->boolean('winning_proof');
|
||||
$table->string('company');
|
||||
$table->text('analytics');
|
||||
$table->text('analytics')->nullable();
|
||||
$table->timestamps();
|
||||
$table->collation = 'utf8mb4_unicode_ci';
|
||||
});
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
<input type="text" name="firstname" class="form-control col-md-6" placeholder="Prénom" value="{{ old('firstname') }}" required>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-md-6 col-form-label">Date de naissance <span class="required-asterisk">*</span></label>
|
||||
<label class="col-md-6 col-form-label">Date de naissance (JJ/MM/AAAA) <span class="required-asterisk">*</span></label>
|
||||
<input type="date" name="birth_date" class="form-control col-md-6" placeholder="Date de naissance" value="{{ old('birth_date') }}" required>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue