so->sendBaseline($this->so->co,GREEN.'Select User Name'.WHITE); } /** * Handle Registration Form Input * * This function assumes the form has 7 fields in a specific order. * * @todo Make this form more dynamic, or put some configuration in a config file, so that there is flexibility * in field placement. * @param string $read * @param array $current * @return string */ public function handle(string $read,array $current=[]) { // If we got a # we'll be completing field input. if ($read == HASH OR $read == LF) { // Does our field have data... if (array_get($current['fielddata'],$current['fieldnum'])) { switch ($current['fieldnum']) { // Username case 0: // See if the requested username already exists if (User::where('login', $current['fielddata'][$current['fieldnum']])->exists()) { $this->so->sendBaseline($this->so->co,RED.'USER ALREADY EXISTS'.WHITE); return ''; } $this->data['user'] = $current['fielddata'][$current['fieldnum']]; $this->so->sendBaseline($this->so->co,GREEN.'Enter Real Name'.WHITE); break; // Real Name case 1: $this->data['name'] = $current['fielddata'][$current['fieldnum']]; $this->so->sendBaseline($this->so->co,GREEN.'Enter Email Address'.WHITE); break; // Email Address case 2: if (Validator::make(['email'=>$current['fielddata'][$current['fieldnum']]],[ 'email'=>'email', ])->fails()) { $this->so->sendBaseline($this->so->co,RED.'INVALID EMAIL ADDRESS'.WHITE); return ''; }; // See if the requested email already exists if (User::where('email', $current['fielddata'][$current['fieldnum']])->exists()) { $this->so->sendBaseline($this->so->co,RED.'USER ALREADY EXISTS'.WHITE); return ''; } $this->data['email'] = $current['fielddata'][$current['fieldnum']]; $this->data['token'] = sprintf('%06.0f',rand(0,999999)); $this->so->sendBaseline($this->so->co,YELLOW.'PROCESSING...'.WHITE); Mail::to($this->data['email'])->sendNow(new SendToken($this->data['token'])); if (Mail::failures()) { dump('Failure?'); dump(Mail::failures()); } $this->so->sendBaseline($this->so->co,GREEN.'Enter Password'.WHITE); break; // Enter Password case 3: $this->data['password'] = $current['fielddata'][$current['fieldnum']]; $this->so->sendBaseline($this->so->co,GREEN.'Confirm Password'.WHITE); break; // Confirm Password case 4: if ($this->data['password'] !== $current['fielddata'][$current['fieldnum']]) { $this->so->sendBaseline($this->so->co,RED.'PASSWORD DOESNT MATCH, *09 TO START AGAIN'.WHITE); return ''; } $this->so->sendBaseline($this->so->co,GREEN.'Enter Location'.WHITE); break; // Enter Location case 5: $this->data['location'] = $current['fielddata'][$current['fieldnum']]; $this->so->sendBaseline($this->so->co,GREEN.'Enter TOKEN emailed to you'.WHITE); break; // Enter Token case 6: if ($this->data['token'] !== $current['fielddata'][$current['fieldnum']]) { $this->so->sendBaseline($this->so->co,RED.'TOKEN DOESNT MATCH, *09 TO START AGAIN'.WHITE); return ''; } break; default: $this->so->sendBaseline($this->so->co,RED.'HUH?'); } } else { // If we are MODE_BL, we need to return the HASH, otherwise nothing. if (in_array($this->state['mode'],[MODE_BL,MODE_SUBMITRF,MODE_RFNOTSENT])) { return $read; } else { $this->so->sendBaseline($this->so->co,RED.'FIELD REQUIRED...'.WHITE); return ''; } } } return $read; } public function process() { $o = new User; try { $o->login = $this->data['user']; $o->email = $this->data['email']; $o->password = $this->data['password']; $o->name = $this->data['name']; $o->location = $this->data['location']; $o->save(); $this->so->sendBaseline($this->so->co,GREEN.'ACCOUNT CREATED, PRESS '.HASH.' TO CONTINUE...'.WHITE); $this->state['action'] = ACTION_NEXT; // Add to CUG 0 $o->cugs()->attach(0); } catch (\Exception $e) { $this->so->sendBaseline($this->so->co,RED.'SOMETHING WENT WRONG...'.WHITE); $this->so->log('error',$e->getMessage()); $this->state['action'] = ACTION_RELOAD; } $this->complete = TRUE; } }