コード例 #1
0
 public function edit($id = '')
 {
     /***********************************
     		Edit form
     		************************************/
     $this->f3->scrub($_POST);
     $members = new Members($this->db);
     $this->f3->set('member', $members->read(array('id=?', $id), [])[0]);
     $this->f3->set('SESSION.flash', array());
     $this->f3->set('status', array('Active', 'Hiatus'));
     $cards = new Cards($this->db);
     $this->f3->set('decks', $cards->allAlpha());
     $this->f3->set('months', array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'));
     // form submitted
     if ($this->f3->exists('POST.edit')) {
         $audit = \Audit::instance();
         // validate form
         if (!preg_match("/^[\\w\\-]{2,30}\$/", $this->f3->get('POST.name'))) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid name. Only letters, numbers, underscores (_), and dashes (-) are allowed.'));
         }
         if (!$audit->email($this->f3->get('POST.email'), FALSE)) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid email address'));
         }
         if (!$audit->url($this->f3->get('POST.url'))) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid trade post URL.'));
         }
         if (!in_array($this->f3->get('POST.birthday'), $this->f3->get('months'))) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid birthday'));
         }
         if ($cards->count(array('id=?', $this->f3->get('POST.collecting'))) == 0) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid collecting deck.'));
         }
         if ($this->f3->get('member')->status !== 'Pending' && !in_array($this->f3->get('POST.status'), $this->f3->get('status'))) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid status.'));
         }
         // if there are no errors, process the form
         if (count($this->f3->get('SESSION.flash')) === 0) {
             $this->f3->set('collectingID', $this->f3->get('POST.collecting'));
             $this->f3->set('POST.collecting', $cards->getById($this->f3->get('POST.collecting'))->filename);
             if ($members->edit($this->f3->get('POST.id'))) {
                 $this->f3->push('SESSION.flash', array('type' => 'success', 'msg' => 'Member ' . $this->f3->get('POST.name') . ' edited!'));
                 $this->f3->reroute('/mytcg/members');
             } else {
                 $this->f3->push('SESSION.flash', array('type' => 'danger', 'msg' => 'There was a problem processing your request. Please try again!'));
             }
         }
     }
     $this->f3->set('content', 'app/views/mytcg/members_edit.htm');
     echo Template::instance()->render('app/templates/admin.htm');
 }
コード例 #2
0
ファイル: FormsController.php プロジェクト: Renako/mytcg-f3
 private function master()
 {
     /***********************************
     		Process Deck Mastery Form! 
     		************************************/
     $this->f3->scrub($_POST);
     $members = new Members($this->db);
     $cards = new Cards($this->db);
     $this->f3->set('member', $members->read(array('id=?', $this->f3->get('SESSION.userID')), [])[0]);
     $this->f3->set('SESSION.flash', array());
     // validate form
     if ($cards->count(array('id=?', $this->f3->get('POST.mastered'))) == 0) {
         $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid mastered deck.'));
     }
     if ($cards->count(array('id=?', $this->f3->get('POST.collecting'))) == 0) {
         $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid collecting deck.'));
     }
     $i = 0;
     foreach ($this->f3->get('POST.choiceDeck') as $deck) {
         $num = $i + 1;
         if ($cards->count(array('id=?', $deck)) == 0) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Choice card #' . $num . ' is invalid.'));
         }
         if ($cards->read(array('id=?', $deck), [])[0]['count'] < intval($this->f3->get('POST.choiceNum[' . $i . ']'))) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Choice card #' . $num . ' is not a valid number.'));
         }
         $i++;
     }
     // if there are no errors, process the form
     if (count($this->f3->get('SESSION.flash')) === 0) {
         $this->f3->set('masteredID', $this->f3->get('POST.mastered'));
         $this->f3->set('POST.mastered', $cards->getById($this->f3->get('POST.mastered'))->filename);
         $this->f3->set('collectingID', $this->f3->get('POST.collecting'));
         $this->f3->set('POST.collecting', $cards->getById($this->f3->get('POST.collecting'))->filename);
         $mailer = new Mailer();
         $message = $mailer->message()->setSubject($this->f3->get('tcgname') . ': ' . $this->f3->get('member')->name . ' Mastered ' . $this->f3->get('POST.mastered') . '!')->setFrom(array($this->f3->get('noreplyemail') => 'MyTCG'))->setTo(array($this->f3->get('tcgemail')))->setReplyTo(array($this->f3->get('member')->email))->setBody(Template::instance()->render('app/templates/emails/mastery-notif.htm'), 'text/html');
         if ($mailer->send($message) && $members->edit($this->f3->get('SESSION.userID'), array('collecting'))) {
             $this->f3->set('member', $members->read(array('id=?', $this->f3->get('SESSION.userID')), [])[0]);
             $this->f3->set('rewardType', 'Deck Mastery');
             // Generate rewards!
             $this->f3->set('rewards', array());
             // choice cards
             for ($i = 0; $i < $this->f3->get('num_maschoice'); $i++) {
                 $this->f3->push('rewards', $cards->read(array('id=?', $this->f3->get('POST.choiceDeck[' . $i . ']')), [])[0]->filename . str_pad($this->f3->get('POST.choiceNum[' . $i . ']'), 2, "0", STR_PAD_LEFT));
             }
             // random regular cards
             for ($i = 0; $i < $this->f3->get('num_masreg'); $i++) {
                 $this->f3->push('rewards', $cards->random(array('worth=?', 1)));
             }
             // random special cards
             for ($i = 0; $i < $this->f3->get('num_masspc'); $i++) {
                 $this->f3->push('rewards', $cards->random(array('worth=?', 2)));
             }
             $log = '[' . date("D, d M Y H:i:s") . '] <strong>Deck Mastery (' . $this->f3->get('POST.mastered') . ')</strong>: ' . implode(', ', $this->f3->get('rewards'));
             $logger = new Logger();
             $logger->push($this->f3->get('SESSION.userID'), $log);
             $mailer = new Mailer();
             $message = $mailer->message()->setSubject($this->f3->get('tcgname') . ': Mastered ' . $this->f3->get('POST.mastered'))->setFrom(array($this->f3->get('noreplyemail') => $this->f3->get('tcgname')))->setTo(array($this->f3->get('member')->email))->setReplyTo(array($this->f3->get('tcgemail')))->setBody(Template::instance()->render('app/templates/emails/mastery.htm'), 'text/html');
             $result = $mailer->send($message);
         } else {
             $this->f3->push('SESSION.flash', array('type' => 'danger', 'msg' => 'There was a problem processing your request. Please try again or contact us for assistance!'));
         }
     }
 }
コード例 #3
0
ファイル: MembersController.php プロジェクト: Renako/mytcg-f3
 public function settings()
 {
     if ($this->f3->exists('SESSION.userID')) {
         $cards = new Cards($this->db);
         $members = new Members($this->db);
         $this->f3->set('status', array('Active', 'Hiatus'));
         $this->f3->set('decks', $cards->allAlpha());
         $this->f3->set('member', $members->read(array('id=?', $this->f3->get('SESSION.userID')), [])[0]);
         if ($this->f3->exists('POST.update')) {
             $audit = \Audit::instance();
             $this->f3->scrub($_POST);
             $this->f3->set('SESSION.flash', array());
             // validate form
             if (!$audit->email($this->f3->get('POST.email'), FALSE)) {
                 $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid email address.'));
             }
             if ($this->f3->get('POST.email') != $this->f3->get('member')->email && $members->count(array('email=?', $this->f3->get('POST.email'))) != 0) {
                 $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Your email address is already in use by another player.'));
             }
             if (!$audit->url($this->f3->get('POST.url'))) {
                 $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid trade post URL.'));
             }
             if ($this->f3->get('POST.password') !== '' && !preg_match("/^.{6,}\$/", $this->f3->get('POST.password'))) {
                 $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Your password must contain at least 6 characters.'));
             }
             if ($this->f3->get('POST.password') !== '' && $this->f3->get('POST.password') !== $this->f3->get('POST.password2')) {
                 $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Your passwords don\'t match!'));
             }
             if ($this->f3->get('member')->status !== 'Pending' && !in_array($this->f3->get('POST.status'), $this->f3->get('status'))) {
                 $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid status.'));
             }
             if ($cards->count(array('id=?', $this->f3->get('POST.collecting'))) == 0) {
                 $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid collecting deck.'));
             }
             if (!preg_match("/^.{0,875}\$/", $this->f3->get('POST.biography')) || !preg_match("/^.{0,875}\$/", $this->f3->get('POST.wishlist'))) {
                 $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Please limit your Profile details to 875 characters.'));
             }
             // process form if there are no errors
             if (count($this->f3->get('SESSION.flash')) === 0) {
                 if ($this->f3->get('member')->status == 'Pending') {
                     // If they're pending, don't let them change their status!
                     $this->f3->set('POST.status', 'Pending');
                 }
                 if ($this->f3->exists('POST.password') && $this->f3->get('POST.password') != '') {
                     // if password was changed, hash it
                     $this->f3->set('POST.password', password_hash($this->f3->get('POST.password'), PASSWORD_DEFAULT));
                 } else {
                     $this->f3->clear('POST.password');
                 }
                 $this->f3->set('collectingID', $this->f3->get('POST.collecting'));
                 $this->f3->set('POST.collecting', $cards->getById($this->f3->get('POST.collecting'))->filename);
                 // update settings in db
                 if ($members->edit($this->f3->get('SESSION.userID'), array('email', 'url', 'status', 'password', 'level', 'collecting', 'wishlist', 'biography'))) {
                     $this->f3->push('SESSION.flash', array('type' => 'success', 'msg' => 'Your settings have been updated!'));
                     $this->f3->set('member', $members->read(array('id=?', $this->f3->get('SESSION.userID')), [])[0]);
                 } else {
                     $this->f3->push('SESSION.flash', array('type' => 'danger', 'msg' => 'There was a problem processing your request. Please try again or contact us for assistance!'));
                 }
             }
         }
         $this->f3->set('content', 'app/views/settings.htm');
         echo Template::instance()->render('app/templates/default.htm');
     } else {
         $this->f3->reroute('/members/login');
     }
 }
コード例 #4
0
ファイル: JoinController.php プロジェクト: Renako/mytcg-f3
 public function index()
 {
     $cards = new Cards($this->db);
     $members = new Members($this->db);
     $this->f3->set('months', array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'));
     if ($this->f3->exists('POST.join')) {
         $audit = \Audit::instance();
         $this->f3->scrub($_POST);
         $this->f3->set('SESSION.flash', array());
         // validate form
         if (!preg_match("/^[\\w\\-]{2,30}\$/", $this->f3->get('POST.name'))) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid name. Only letters, numbers, underscores (_), and dashes (-) are allowed.'));
         }
         if ($members->count(array('name=?', $this->f3->get('POST.name'))) != 0) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Your name is already taken by another player. Please select a different name and try again!'));
         }
         if (!$audit->email($this->f3->get('POST.email'), FALSE)) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid email address'));
         }
         if ($members->count(array('email=?', $this->f3->get('POST.email'))) != 0) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Your email address is already in use by another player.'));
         }
         if (!$audit->url($this->f3->get('POST.url'))) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid trade post URL.'));
         }
         if (!preg_match("/^.{6,}\$/", $this->f3->get('POST.password'))) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Your password must contain at least 6 characters.'));
         }
         if ($this->f3->get('POST.password') !== $this->f3->get('POST.password2')) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Your passwords don\'t match!'));
         }
         if (!in_array($this->f3->get('POST.birthday'), $this->f3->get('months'))) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid birthday'));
         }
         if ($cards->count(array('id=?', $this->f3->get('POST.collecting'))) == 0) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid collecting deck.'));
         }
         if ($this->f3->get('POST.refer') !== '' && $members->count(array('name=?', $this->f3->get('POST.refer'))) == 0) {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Invalid referral - that player\'s name doesn\'t exist in our database. Please check your spelling and try again!'));
         }
         // honey pot
         if ($this->f3->get('POST.username') !== '') {
             $this->f3->push('SESSION.flash', array('type' => 'warning', 'msg' => 'Please do not use autofill or similar tools!'));
         }
         // process form if there are no errors
         if (count($this->f3->get('SESSION.flash')) === 0) {
             $this->f3->set('POST.status', 'Pending');
             $this->f3->set('POST.level', 1);
             $this->f3->set('POST.membercard', 'No');
             $this->f3->set('POST.mastered', 'None');
             $this->f3->set('POST.wishlist', 'Coming soon.');
             $this->f3->set('POST.biography', 'Coming soon.');
             $this->f3->set('POST.password', password_hash($this->f3->get('POST.password'), PASSWORD_DEFAULT));
             $this->f3->set('collectingID', $this->f3->get('POST.collecting'));
             $this->f3->set('POST.collecting', $cards->getById($this->f3->get('POST.collecting'))->filename);
             $mailer = new Mailer();
             $message = $mailer->message()->setSubject($this->f3->get('tcgname') . ': New Member')->setFrom(array($this->f3->get('noreplyemail') => 'MyTCG'))->setTo(array($this->f3->get('tcgemail')))->setReplyTo(array($this->f3->get('POST.email')))->setBody(Template::instance()->render('app/templates/emails/newmember.htm'), 'text/html');
             // send email & save to db
             if ($mailer->send($message) && $members->add()) {
                 $this->f3->set('sp', array());
                 // random choice cards
                 for ($i = 0; $i < $this->f3->get('num_startchoice'); $i++) {
                     $this->f3->push('sp', $cards->random(array('id=?', $this->f3->get('collectingID'))));
                 }
                 // random regular cards
                 for ($i = 0; $i < $this->f3->get('num_startreg'); $i++) {
                     $this->f3->push('sp', $cards->random(array('worth=?', 1)));
                 }
                 // random special cards
                 for ($i = 0; $i < $this->f3->get('num_startspc'); $i++) {
                     $this->f3->push('sp', $cards->random(array('worth=?', 2)));
                 }
                 $mailer = new Mailer();
                 $message = $mailer->message()->setSubject($this->f3->get('tcgname') . ': Starter Pack')->setFrom(array($this->f3->get('noreplyemail') => $this->f3->get('tcgname')))->setTo(array($this->f3->get('POST.email')))->setReplyTo(array($this->f3->get('tcgemail')))->setBody(Template::instance()->render('app/templates/emails/starterpack.htm'), 'text/html');
                 $result = $mailer->send($message);
                 // load welcome message
                 $this->f3->set('content', 'app/views/welcome.htm');
             } else {
                 $this->f3->push('SESSION.flash', array('type' => 'danger', 'msg' => 'There was a problem processing your request. Please try again or contact us for assistance!'));
             }
         }
     }
     if (!$this->f3->exists('content')) {
         $this->f3->set('content', 'app/views/join.htm');
     }
     $this->f3->set('decks', $cards->allAlpha());
     echo Template::instance()->render('app/templates/default.htm');
 }