Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Create a new account
- *
- * @param mixed $data Posted form data
- * @param int $captcha Randomly generated code
- */
- public function create($request)
- {
- $this->request = (object) $request;
- $allowed_states = array('US', 'CA', 'AF', 'AL', 'DZ', 'DS', 'AD', 'AO', 'AI', 'AQ', 'AG', 'AR', 'AM', 'AW', 'AU', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB', 'BY', 'BE', 'BZ', 'BJ', 'BM', 'BT', 'BO', 'BA', 'BW', 'BV', 'BR', 'IO', 'BN', 'BG', 'BF', 'BI', 'KH', 'CM', 'CV', 'KY', 'CF', 'TD', 'CL', 'CN', 'CX', 'CC', 'CO', 'KM', 'CG', 'CK', 'CR', 'HR', 'CU', 'CY', 'CZ', 'DK', 'DJ', 'DM', 'DO', 'TP', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE', 'ET', 'FK', 'FO', 'FJ', 'FI', 'FR', 'FX', 'GF', 'PF', 'TF', 'GA', 'GM', 'GE', 'DE', 'GH', 'GI', 'GR', 'GL', 'GD', 'GP', 'GU', 'GT', 'GN', 'GW', 'GY', 'HT', 'HM', 'HN', 'HK', 'HU', 'IS', 'IN', 'ID', 'IR', 'IQ', 'IE', 'IL', 'IT', 'CI', 'JM', 'JP', 'JO', 'KZ', 'KE', 'KI', 'KP', 'KR', 'XK', 'KW', 'KG', 'LA', 'LV', 'LB', 'LS', 'LR', 'LY', 'LI', 'LT', 'LU', 'MO', 'MK', 'MG', 'MW', 'MY', 'MV', 'ML', 'MT', 'MH', 'MQ', 'MR', 'MU', 'TY', 'MX', 'FM', 'MD', 'MC', 'MN', 'ME', 'MS', 'MA', 'MZ', 'MM', 'NA', 'NR', 'NP', 'NL', 'AN', 'NC', 'NZ', 'NI', 'NE', 'NG', 'NU', 'NF', 'MP', 'NO', 'OM', 'PK', 'PW', 'PA', 'PG', 'PY', 'PE', 'PH', 'PN', 'PL', 'PT', 'PR', 'QA', 'RE', 'RO', 'RU', 'RW', 'KN', 'LC', 'VC', 'WS', 'SM', 'ST', 'SA', 'SN', 'RS', 'SC', 'SL', 'SG', 'SK', 'SI', 'SB', 'SO', 'ZA', 'GS', 'ES', 'LK', 'SH', 'PM', 'SD', 'SR', 'SJ', 'SZ', 'SE', 'CH', 'SY', 'TW', 'TJ', 'TZ', 'TH', 'TG', 'TK', 'TO', 'TT', 'TN', 'TR', 'TM', 'TC', 'TV', 'UG', 'UA', 'AE', 'GB', 'UM', 'UY', 'UZ', 'VU', 'VA', 'VE', 'VN', 'VG', 'VI', 'WF', 'EH', 'YE', 'YU', 'ZR', 'ZM', 'ZW');
- $_SESSION['request_form'] = $request;
- $clients = DB::table('clients')->get();
- $clients->each(function($client){
- $data = json_decode($client->data, true);
- if($data['client_info']['email'] == $this->request->client_email){
- echo throw_alert('Nastala chyba!', "Tato emailová adresa ({$this->request->client_email}) je již využita jiným uživatelem.", 'danger');
- $this->isError = true;
- }
- });
- $unfilled = [];
- if(!in_array($this->request->client_state, $allowed_states)){
- echo throw_alert('Nastala chyba!', "Vybraný stát není možno akceptovat.", 'danger');
- $this->isError = true;
- }
- if(!isset($this->request->client_firstname)){
- $unfilled[] = 'křestní jméno';
- }
- if(!isset($this->request->client_lastname)){
- $unfilled[] = 'příjmení';
- }
- if(!isset($this->request->client_email)){
- $unfilled[] = 'emailová adresa';
- }
- if(!isset($this->request->client_password)){
- $unfilled[] = 'heslo';
- }
- if(!isset($this->request->client_password_check)){
- $unfilled[] = 'heslo (kontrola)';
- }
- if(!isset($this->request->client_city)){
- $unfilled[] = 'město/obec, ulice a číslo popisné';
- }
- if(!isset($this->request->client_zip)){
- $unfilled[] = 'psč';
- }
- if(!isset($this->request->vop_accept)){
- echo throw_alert('Nastala chyba!', "Touto registrací musíte souhlasit s VOP.", 'danger');
- $this->isError = true;
- }
- if(!isset($this->request->client_captcha)){
- $unfilled[] = 'captcha';
- }
- if($this->request->client_captcha != $_SESSION['server_captcha']){
- echo throw_alert('Nastala chyba!', "Zadaný captcha kód je neplatný.", 'danger');
- $this->isError = true;
- }
- if(str_contains_helper($this->request->client_zip, ' ')){
- $zip_parse = explode(' ', $this->request->client_zip);
- if(!is_numeric($zip_parse[0].$zip_parse[1])){
- echo throw_alert('Nastala chyba!', "Zadané PSČ je neplatné.", 'danger');
- $this->isError = true;
- }
- }else{
- if(!is_numeric($this->request->client_zip)){
- echo throw_alert('Nastala chyba!', "Zadané PSČ je neplatné.", 'danger');
- $this->isError = true;
- }
- }
- if($this->request->client_password != $this->request->client_password_check){
- echo throw_alert('Nastala chyba!', "Zadaná hesla, která jste zadal, nejsou shodná.", 'danger');
- $this->isError = true;
- }
- if(!filter_var($this->request->client_email, FILTER_VALIDATE_EMAIL)){
- echo throw_alert('Nastala chyba!', "Tato emailová adresa ({$this->request->client_email}) není platná.", 'danger');
- $this->isError = true;
- }
- if(count($unfilled) > 0){
- $error_text = "{0} [{1}] {2}";
- for($i=0;$i<count($unfilled);$i++){
- if(count($unfilled) > 1){
- $error_text = str_replace('{0}', 'Tyto políčka', $error_text);
- $error_text = str_replace('{2}', 'nejsou vyplněná.', $error_text);
- }else{
- $error_text = str_replace('{0}', 'Toto políčko', $error_text);
- $error_text = str_replace('{2}', 'není vyplněné.', $error_text);
- }
- $error_text = str_replace('{1}', implode(',', $unfilled), $error_text);
- }
- echo throw_alert('Nastala chyba!', $error_text, 'danger');
- $this->isError = true;
- }
- $structure = json_encode([
- 'client_info' => [
- 'email' => $this->request->client_email,
- 'password' => hash('sha256', $this->request->client_password)
- ],
- 'client_data' => [
- 'balancne' => 0,
- 'permissions' => 0
- ],
- 'billing_info' => [
- 'first_name' => $this->request->client_firstname,
- 'last_name' => $this->request->client_lastname,
- 'state' => $this->request->client_state,
- 'city' => $this->request->client_city,
- 'zip' => $this->request->client_zip,
- 'phone' => $this->request->client_phone
- ]
- ]);
- if($this->isError == false){
- \App\Client::insert(['data' => $structure]);
- echo throw_alert('Úspěch!', 'Váš uživatelský účet byl zaregistrován. Přihlásit se je možno <a href="/client/login">zde</a>.', 'success');
- unset($_SESSION['request_form']);
- unset($_SESSION['server_captcha']);
- redirect_to('/client/login', 3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement