diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index b2ea669..191b2b6 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -25,7 +25,7 @@ class LoginController extends Controller * * @var string */ - protected $redirectTo = '/home'; + protected $redirectTo = '/'; /** * Create a new controller instance. diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php deleted file mode 100644 index 6fdcba0..0000000 --- a/app/Http/Controllers/Auth/RegisterController.php +++ /dev/null @@ -1,72 +0,0 @@ -middleware('guest'); - } - - /** - * Get a validator for an incoming registration request. - * - * @param array $data - * @return \Illuminate\Contracts\Validation\Validator - */ - protected function validator(array $data) - { - return Validator::make($data, [ - 'name' => ['required', 'string', 'max:255'], - 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], - 'password' => ['required', 'string', 'min:8', 'confirmed'], - ]); - } - - /** - * Create a new user instance after a valid registration. - * - * @param array $data - * @return \App\User - */ - protected function create(array $data) - { - return User::create([ - 'name' => $data['name'], - 'email' => $data['email'], - 'password' => Hash::make($data['password']), - ]); - } -} diff --git a/app/Http/Controllers/Auth/VerificationController.php b/app/Http/Controllers/Auth/VerificationController.php deleted file mode 100644 index 23a43a8..0000000 --- a/app/Http/Controllers/Auth/VerificationController.php +++ /dev/null @@ -1,41 +0,0 @@ -middleware('auth'); - $this->middleware('signed')->only('verify'); - $this->middleware('throttle:6,1')->only('verify', 'resend'); - } -} diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php deleted file mode 100644 index 7cbc2c3..0000000 --- a/app/Http/Controllers/HomeController.php +++ /dev/null @@ -1,28 +0,0 @@ -middleware('auth'); - } - - /** - * Show the application dashboard. - * - * @return \Illuminate\Contracts\Support\Renderable - */ - public function index() - { - return view('home'); - } -} diff --git a/app/Http/Controllers/InscriptionController.php b/app/Http/Controllers/InscriptionController.php new file mode 100644 index 0000000..b7a982f --- /dev/null +++ b/app/Http/Controllers/InscriptionController.php @@ -0,0 +1,72 @@ +with([ + "programs" => Program::all(), + "interests" => Interest::all(), + "communicationMethods" => CommunicationMethod::all() + ]); + } + + public function postInscription(Request $request) + { + $this->validator($request->all())->validate(); + + $member = $this->create($request->all()); + + return view('inscription')->with([ + 'member' => $member + ]); + } + + protected function validator(array $data) + { + return Validator::make($data, [ + 'first_name' => ['required', 'string', 'max:255'], + 'last_name' => ['required', 'string', 'max:255'], + 'email' => ['required', 'string', 'email', 'max:255', 'unique:members'], + 'universal_code' => ['required', 'string', 'max:255'], + 'phone' => ['sometimes', new PhoneRule], + 'program_id' => ['required', 'integer'] + ]); + } + + protected function create(array $data) + { + return Member::create([ + 'first_name' => $data['first_name'], + 'last_name' => $data['last_name'], + 'email' => $data['email'], + 'universal_code' => $data['universal_code'], + 'start_semester' => Member::getSemesterLetter().date("Y"), + 'activity' => Member::ACTIVITY[0], + 'phone' => $data['phone'], + 'program_id' => $data['program_id'] + ]); + } +} diff --git a/app/Http/Controllers/MailController.php b/app/Http/Controllers/MailController.php new file mode 100644 index 0000000..5824360 --- /dev/null +++ b/app/Http/Controllers/MailController.php @@ -0,0 +1,22 @@ +get(); + Mail::to($member->email)->send(new InscriptionMail($member, $laboratories)); + } +} diff --git a/app/Mail/InscriptionMail.php b/app/Mail/InscriptionMail.php new file mode 100644 index 0000000..80f0aca --- /dev/null +++ b/app/Mail/InscriptionMail.php @@ -0,0 +1,40 @@ +member = $member; + } + + public function build() + { + $laboratories = LaboratoryType::inscription()->get(); + return $this->from('conjure@etsmtl.ca') + ->view('mails.inscription') + ->with( + [ + "member" => $this->member, + "laboratories" => $laboratories + ]); + } +} diff --git a/app/Models/CommunicationMethod.php b/app/Models/CommunicationMethod.php new file mode 100644 index 0000000..de329b8 --- /dev/null +++ b/app/Models/CommunicationMethod.php @@ -0,0 +1,10 @@ +belongsTo('App\Models\Member'); + } + + public function getStatusAttribute() + { + return self::STATUS[$this->status_id]; + } + + public function laboratoryType() + { + return $this->hasOne('App\Models\LaboratoryType'); + } + + +} diff --git a/app/Models/LaboratoryType.php b/app/Models/LaboratoryType.php new file mode 100644 index 0000000..87a47a9 --- /dev/null +++ b/app/Models/LaboratoryType.php @@ -0,0 +1,38 @@ +status_id]; + } + + public function getTypeAttribute() + { + return self::TYPE[$this->type_id]; + } + + public function laboratory() + { + return $this->belongsTo('App\Models\Laboratory'); + } + + public function scopeInscription($query) + { + return $query->where('status_id', array_search("Actif", self::STATUS)) + ->where('type_id', array_search("Inscription", self::TYPE)); + } +} diff --git a/app/Models/Member.php b/app/Models/Member.php new file mode 100644 index 0000000..2c2fe8a --- /dev/null +++ b/app/Models/Member.php @@ -0,0 +1,74 @@ +activity_id]; + } + + + /* ------------------------------------------------------------------------------------------------ Relationships */ + public function program() + { + return $this->hasOne('App\Models\Program'); + } + + public function laboratory() + { + return $this->hasOne('App\Models\Laboratory'); + } + + public function interests() + { + return $this->hasMany('App\Models\Interest'); + } + + public function communicationMethod() + { + return $this->hasOne('App\Models\CommunicationMethod', "preferred_communication_method_id", 'id'); + } + + + /* ------------------------------------------------------------------------------------------------------- Static */ + public static function getSemesterLetter() + { + $month = date('n'); + if ($month >= 9) { + $semester = "A"; + } + elseif ($month >= 5) { + $semester = "É"; + } + else { + $semester = "H"; + } + + return $semester; + } +} diff --git a/app/Models/Program.php b/app/Models/Program.php new file mode 100644 index 0000000..033b922 --- /dev/null +++ b/app/Models/Program.php @@ -0,0 +1,19 @@ +belongsTo('App\Models\Member'); + } +} diff --git a/app/Rules/PhoneRule.php b/app/Rules/PhoneRule.php new file mode 100644 index 0000000..a198d64 --- /dev/null +++ b/app/Rules/PhoneRule.php @@ -0,0 +1,42 @@ += 10; + return true; + } + + /** + * Get the validation error message. + * + * @return string + */ + public function message() + { + return trans('validation.phone'); + } +} diff --git a/app/User.php b/app/User.php index e79dab7..0dd9b57 100644 --- a/app/User.php +++ b/app/User.php @@ -16,7 +16,7 @@ class User extends Authenticatable * @var array */ protected $fillable = [ - 'name', 'email', 'password', + 'password', ]; /** @@ -36,4 +36,9 @@ class User extends Authenticatable protected $casts = [ 'email_verified_at' => 'datetime', ]; + + public function member() + { + return $this->hasOne("App\Models\Member"); + } } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php deleted file mode 100644 index 084535f..0000000 --- a/database/factories/UserFactory.php +++ /dev/null @@ -1,27 +0,0 @@ -define(User::class, function (Faker $faker) { - return [ - 'name' => $faker->name, - 'email' => $faker->unique()->safeEmail, - 'email_verified_at' => now(), - 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password - 'remember_token' => Str::random(10), - ]; -}); diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index a91e1d3..54689fd 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -15,9 +15,7 @@ class CreateUsersTable extends Migration { Schema::create('users', function (Blueprint $table) { $table->bigIncrements('id'); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); + $table->bigInteger('member_id'); $table->string('password'); $table->rememberToken(); $table->timestamps(); diff --git a/database/migrations/2019_09_29_151424_create_programs_table.php b/database/migrations/2019_09_29_151424_create_programs_table.php new file mode 100644 index 0000000..f117edf --- /dev/null +++ b/database/migrations/2019_09_29_151424_create_programs_table.php @@ -0,0 +1,33 @@ +bigIncrements('id'); + $table->string("acronym", 50); + $table->string("name"); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('programs'); + } +} diff --git a/database/migrations/2019_09_29_153557_create_members_table.php b/database/migrations/2019_09_29_153557_create_members_table.php new file mode 100644 index 0000000..71bbabb --- /dev/null +++ b/database/migrations/2019_09_29_153557_create_members_table.php @@ -0,0 +1,44 @@ +bigIncrements('id'); + $table->string("first_name"); + $table->string("last_name"); + $table->string("email")->unique(); + $table->string("universal_code", 7); + $table->string("phone")->nullable(); + $table->string("start_semester"); + $table->string("last_semester")->nullable(); + $table->integer("program_id"); + $table->integer("laboratory_id")->nullable(); + $table->integer("activity"); + + $table->text("expectation")->nullable(); + $table->integer("preferred_communication_method_id")->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('members'); + } +} diff --git a/database/migrations/2019_09_29_171835_create_interests_table.php b/database/migrations/2019_09_29_171835_create_interests_table.php new file mode 100644 index 0000000..6a007fb --- /dev/null +++ b/database/migrations/2019_09_29_171835_create_interests_table.php @@ -0,0 +1,32 @@ +bigIncrements('id'); + $table->string("name"); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('interests'); + } +} diff --git a/database/migrations/2019_09_29_195938_create_commnucation_methods_table.php b/database/migrations/2019_09_29_195938_create_commnucation_methods_table.php new file mode 100644 index 0000000..0e55708 --- /dev/null +++ b/database/migrations/2019_09_29_195938_create_commnucation_methods_table.php @@ -0,0 +1,32 @@ +bigIncrements('id'); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('communication_methods'); + } +} diff --git a/database/migrations/2019_10_12_185138_create_laboratories_table.php b/database/migrations/2019_10_12_185138_create_laboratories_table.php new file mode 100644 index 0000000..4e67208 --- /dev/null +++ b/database/migrations/2019_10_12_185138_create_laboratories_table.php @@ -0,0 +1,33 @@ +bigIncrements('id'); + $table->integer('status_id')->default(0); + $table->integer('laboratory_type_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('laboratories'); + } +} diff --git a/database/migrations/2019_10_12_185138_create_laboratory_types_table.php b/database/migrations/2019_10_12_185138_create_laboratory_types_table.php new file mode 100644 index 0000000..0aad485 --- /dev/null +++ b/database/migrations/2019_10_12_185138_create_laboratory_types_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->integer('status_id')->default(0); + $table->string("name"); + $table->integer("type_id"); + $table->string("engine"); + $table->string('url'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('laboratory_types'); + } +} diff --git a/database/seeds/CommunicationMethodTableSeeder.php b/database/seeds/CommunicationMethodTableSeeder.php new file mode 100644 index 0000000..bccc2f0 --- /dev/null +++ b/database/seeds/CommunicationMethodTableSeeder.php @@ -0,0 +1,26 @@ +truncate(); + + foreach($this->data as $value) { + DB::table('communication_methods')->insert([ + 'name' => $value, + ]); + } + } +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 91cb6d1..9023296 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -11,6 +11,8 @@ class DatabaseSeeder extends Seeder */ public function run() { - // $this->call(UsersTableSeeder::class); + $this->call(CommunicationMethodTableSeeder::class); + $this->call(ProgramTableSeeder::class); + $this->call(DefaultUserTableSeeder::class); } } diff --git a/database/seeds/DefaultUserTableSeeder.php b/database/seeds/DefaultUserTableSeeder.php new file mode 100644 index 0000000..9790045 --- /dev/null +++ b/database/seeds/DefaultUserTableSeeder.php @@ -0,0 +1,39 @@ +truncate(); + DB::table('users')->truncate(); + + foreach($this->members as $key => $data) { + \App\Models\Member::create([ + "first_name" => $data[0], + "last_name" => $data[1], + "email" => $data[2], + "universal_code" => $data[3], + "start_semester" => $data[4], + "program_id" => $data[5], + "activity" => $data[6], + "preferred_communication_method_id" => $data[7] + ]); + + \App\User::create([ + "member_id" => $key + 1, + "password" => \Illuminate\Support\Facades\Hash::make(strtolower($data[0][0].$data[1])."-".$data[4]."&".\App\Models\Program::where("id", $data[5])->first()["acronym"]) + ]); + } + } +} diff --git a/database/seeds/ProgramTableSeeder.php b/database/seeds/ProgramTableSeeder.php new file mode 100644 index 0000000..d348344 --- /dev/null +++ b/database/seeds/ProgramTableSeeder.php @@ -0,0 +1,35 @@ +truncate(); + + foreach($this->data as $value) { + DB::table('programs')->insert([ + 'acronym' => $value[0], + 'name' => $value[1], + ]); + } + } +} diff --git a/resources/lang/en/button.php b/resources/lang/en/button.php new file mode 100644 index 0000000..20fbb4a --- /dev/null +++ b/resources/lang/en/button.php @@ -0,0 +1,10 @@ + "Submit", +]; diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php new file mode 100644 index 0000000..39b1c09 --- /dev/null +++ b/resources/lang/en/general.php @@ -0,0 +1,31 @@ + "Login", + 'logout' => "Logout", + 'password' => "Password", + 'confirm-password' => "Confirm Password", + 'forgot-password' => "Forgot Your Password?", + 'remember-me' => "Remember Me", + 'reset-password' => "Reset Password", + 'send-password-reset-link' => "Send Password Reset Link", + 'inscription' => "Inscription", + 'general-info' => "General Information", + 'first-name' => "First Name", + 'last-name' => "Last Name", + 'email' => "E-Mail", + 'universal-code' => "Universal Code", + 'phone' => "Phone", + 'program' => "Program", + 'others' => "Others", + 'interest' => "Interest", + 'expectation' => "Expectation", + 'communication-method' => "Preferred Communication Method", + + 'choose-option' => "Choose an option" +]; diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index e1d879f..c95be3b 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -116,7 +116,7 @@ return [ 'uploaded' => 'The :attribute failed to upload.', 'url' => 'The :attribute format is invalid.', 'uuid' => 'The :attribute must be a valid UUID.', - + 'phone' => 'The phone number format is invalid.', /* |-------------------------------------------------------------------------- | Custom Validation Language Lines diff --git a/resources/lang/fr/button.php b/resources/lang/fr/button.php new file mode 100644 index 0000000..e1e1393 --- /dev/null +++ b/resources/lang/fr/button.php @@ -0,0 +1,10 @@ + "Envoyer", +]; diff --git a/resources/lang/fr/general.php b/resources/lang/fr/general.php new file mode 100644 index 0000000..9255abc --- /dev/null +++ b/resources/lang/fr/general.php @@ -0,0 +1,31 @@ + "Connexion", + 'logout' => "Déconnexion", + 'password' => "Mot de passe", + 'confirm-password' => "Confirmation du mot de passe", + 'forgot-password' => "Mot de passe oublié?", + 'remember-me' => "Se rappeler de moi", + 'reset-password' => "Réinitialiser le mot de passe", + 'send-password-reset-link' => "Envoyer le lien de réinitialisation de mot de passe", + 'inscription' => "Inscription", + 'general-info' => "Information Générale", + 'first-name' => "Prénom", + 'last-name' => "Nom de famille", + 'email' => "Courriel", + 'universal-code' => "Code Universel", + 'phone' => "Téléphone", + 'program' => "Programme", + 'others' => "Autres", + 'interests' => "Intérêts", + 'expectations' => "Attentes", + 'communication-method' => "Méthode de communication préférée", + + 'choose-option' => "Choisissez une option" +]; diff --git a/resources/lang/fr/validation.php b/resources/lang/fr/validation.php index 11ac012..e35d2d4 100644 --- a/resources/lang/fr/validation.php +++ b/resources/lang/fr/validation.php @@ -116,6 +116,7 @@ return [ 'uploaded' => ':attribute a échoué à téléverser.', 'url' => 'Le format de :attribute est invalide.', 'uuid' => ':attribute doit être un UUID valide.', + 'phone' => 'Le format du numéro de téléphone est invalide.', /* |-------------------------------------------------------------------------- diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index c12b97e..6ab70a0 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -5,14 +5,14 @@