public function postCreate() { $validator = Validator::make(Input::all(), array('first_name' => 'required|max:30', 'last_name' => 'required|max:30', 'city' => 'required|max:30', 'state' => 'required|max:30', 'sex' => 'required', 'school_registration_code' => 'required|max:80', 'user_registration_code' => 'required|max:80', 'email' => 'max:60|email|unique:users', 'password' => 'required|min:6', 'password_again' => 'required|same:password')); if ($validator->fails()) { return Redirect::route('user-account-create')->withErrors($validator)->withInput(); } else { $school_registration_code = Input::get('school_registration_code'); $user_registration_code = Input::get('user_registration_code'); $school = Schools::where('registration_code', '=', $school_registration_code)->where('code_for_students', '=', $user_registration_code)->where('active', '=', 1)->get(); if (!$school->count()) { return Redirect::route('admin-account-create')->with('global', 'Please input Correct School code and Admin Code.'); } $first_name = Input::get('first_name'); $last_name = Input::get('last_name'); $email = Input::get('email'); $sex = Input::get('sex'); $city = Input::get('city'); $state = Input::get('state'); $password = Input::get('password'); // Unique Username $username = substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', mt_rand(1, 10))), 1, 10); //Activation Code $code = str_random(60); $now = date("Y-m-d H-i-s"); $groups = Groups::find(1); $User = User::create(array('first_name' => $first_name, 'last_name' => $last_name, 'email' => $email, 'email_updated_at' => $now, 'password' => Hash::make($password), 'password_updated_at' => $now, 'username' => $username, 'sex' => $sex, 'city' => $city, 'state' => $state, 'address_updated_at' => $now, 'code' => $code, 'active' => 0, 'mobile_verified' => 0, 'permissions' => $groups->id, 'school_id' => $school->first()->id)); if ($User) { //send email Mail::send('emails.auth.activate.activate-user', array('link' => URL::route('user-account-activate', $code), 'username' => $username), function ($message) use($User) { $message->to($User->email, $User->voter_id)->subject('Activate Your Account'); }); return Redirect::route('user-sign-in')->with('global', 'You have been Registered. You can activate Now.'); } else { return Redirect::route('user-sign-in')->with('global', 'You have not Been Registered. Try Again Later Some time.'); } } }
public function postValidateSchool() { $registration_code = Input::get('registration_code'); $group_id = Input::get('group_id'); try { // Find the group using the group id $group = Sentry::findGroupById($group_id); // Get the group permissions $groupPermissions = $group->getPermissions(); } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { echo 'Group does not exist.'; } if ($group->count() > 0) { if ($group->id == 3) { $code_for_teachers = Input::get('code_for_teachers'); $school = Schools::where('registration_code', '=', $registration_code)->where('code_for_teachers', '=', $code_for_teachers)->get()->first(); } elseif ($group_id == 2) { $code_for_students = Input::get('code_for_students'); $school = Schools::where('registration_code', '=', $registration_code)->where('code_for_students', '=', $code_for_students)->get()->first(); } elseif ($group_id == 1) { $code_for_admin = Input::get('code_for_admin'); $school = Schools::where('registration_code', '=', $registration_code)->where('code_for_admin', '=', $code_for_admin)->get()->first(); } if ($school->count() > 0) { $user = Sentry::getUser(); $user->school_id = $school->id; $user->save(); $users_login_info = new UsersLoginInfo(); $users_login_info->user_id = $user->id; $users_login_info->school_id = $school->id; $users_login_info->save(); $response = array('status' => 'success', 'result' => array('school' => $school)); return Response::json($response); } else { $response = array('status' => 'failed', 'result' => array('school' => null)); return Response::json($response); } } }