Skip to content
Snippets Groups Projects

Push SU-APIv2 stuff to live

Merged Imran Hussain requested to merge beta into sucs-site

The code seems to work pretty well on beta.

Do other people want to test it?

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
47 $singuptmpresult = $sucsDB->Execute("SELECT * FROM signup WHERE sid=?", array($sid));
48 } else if ($tmpresult->fields == false && $signuptmpresult->fields["sid"] == $sid) {
49 $mode = "form";
50 $smarty->assign("id",$signuptmpresult->fields["id"]);
51 $smarty->assign("pass",$signuptmpresult->fields["password"]);
52 // else if they aren't in the SUCS DB, then bootstrap signup process
53 } else if ($tmpresult->fields == false && $signuptmpresult->fields == false) {
54 $mode = "form";
55 $pass = make_password();
56 $iddata = $sucsDB->Execute("insert into signup (password,sid,issuedby) values( ?, ?, ?) returning id",array($pass,$sid,"99999"));
57 $id = $iddata->fields['id'];
58 $smarty->assign("id", $id);
59 $smarty->assign("pass", $pass);
60 } else {
61 // they should never get here
62 echo("fuck you");
  • Can I suggest we don't use errors like this in user facing code? Even if it's a case that shouldn't happen, use the proper error handling methods and provide a useful message. Something like "This shouldn't happen, please contact an admin" would do - particularly as the email error reporting code has been removed.

  • There's no possible way to get to that. It requires both the sucssite db and the SUCS db to be unreachable but the site still in a useable enough state to register this component and the new suapi to be working.

    If I had honestly thought anyone would ever be able to see this it would say something so much more useful.

    I'll make a commit go replace it with die("You'll never see this but if you do, something has gone very wrong and the admin team are probably already trying to fix if");

  • Thomas Lake
    Thomas Lake @tswsl1989 started a thread on commit ba01da38
  • 240 $array['emailAddress'].','.$sid.'@swansea.ac.uk',
    241 "SUCS Signup Information",
    242 "Thankyou for joining Swansea University Computer Society, your signup details are below;\nSignupID: $id\nSignup Password: $pass\nIf you have successfully completed signup immediately then you can disregard this message.\n\nSUCS Admin Team.",
    243 "From: \"SUCS Admin\" <admin@sucs.org>"
    244 );
    245 }
    246 }
    247 }
    248 }
    249 }
    32 // check if the data posted is valid
    33 if(check_su_sid_and_trans($sid,$transactionID)){
    34
    35 // check to see if they are already a valid and paid member
    36 $tmpresult = $sucsDB->Execute("SELECT * FROM members WHERE sid=?", array($sid));
    37 if($tmpresult->fields["sid"] == $sid && $tmpresult->fields["paid"] == paidUntil(time())){
    • I think the branches of this if statement need to be reversed. If $tmpresult->fields==false (as checked for in the last two branches), then I this first check may cause an error to be printed. Not the end of the world, but avoidable and better practice.

    • That's a valid point but from my testing. No errors came up when it was done in this order.

      No 100% if it had been my test environment saving me though.

    • Whether or not the errors get shown is going to vary based on the particular PHP settings in use. We might suppress E_NOTICE by default on silver anyway, so you'd only see the errors if you request E_ALL or E_NOTICE specifically. There are definitely other parts of this file that should have been throwing errors during development though (see other comments)

    • I like to use E_ALL when developing php things but it's not always possible with the sucs site as the smarty templating engine will bite you and break the sucs site.

    • Find out where the other errors come from and file a bug for it ;-)

    • files a bug for moving away from smarty

  • Thomas Lake
    Thomas Lake @tswsl1989 started a thread on commit ba01da38
  • 32 // check if the data posted is valid
    33 if(check_su_sid_and_trans($sid,$transactionID)){
    34
    35 // check to see if they are already a valid and paid member
    36 $tmpresult = $sucsDB->Execute("SELECT * FROM members WHERE sid=?", array($sid));
    37 if($tmpresult->fields["sid"] == $sid && $tmpresult->fields["paid"] == paidUntil(time())){
    38 // let them know they are already signed up and renewed
    39 message_flash("You are a numpty and have already signed up and paid for this year.");
    40 // else if check to see if they have signedup and paid for the new year but haven't renewed
    41 }else if ($tmpresult->fields["sid"] == $sid && $tmpresult->fields["paid"] != paidUntil(time())){
    42 // renew them!
    43 renew_membership($tmpresult->fields["username"]);
    44 // let them know that their account has been renewed
    45 message_flash("Your SUCS account has been renewed.");
    46 // else if they aren't in the SUCS DB but have a signup slip, take them back to that part of signup
    47 $singuptmpresult = $sucsDB->Execute("SELECT * FROM signup WHERE sid=?", array($sid));
    • Shouldn't this be $signuptmpresult? It should also be outside the if statements - As far as I can tell it would currently only be executed if the previous else if is true - in which case we don't need it.

  • Thomas Lake
    Thomas Lake @tswsl1989 started a thread on commit ba01da38
  • 107 107 return $ldif;
    108 108 }
    109 109
    110 // function to renew a persons sucs membership
    111 function renew_membership($username) {
    112
    113 // get their details from the sucs db
    114 $userdata = $sucsDB->Execute("SELECT * FROM members WHERE username=?", array($username));
    115
    116 // include the date file so we can call the paidUntil function
    117 include_once("date.php");
    118
    119 // Update their record in the DB
    120 $sucsDB->Execute("UPDATE members SET paid=?, lastupdate=DEFAULT, lastedit=? WHERE username=?", array(paidUntil(time()), "99999", $username));
    • Not checking for success? Failure is unlikely, but would mean that the member won't realise that they haven't actually been renewed in our records.

    • Developer

      I don't have time to finish reviewing this tonight I'm afraid. It's a good start, but there's enough little errors that I would suggest holding off on merging this to beta until its had a proper check through - either by myself when I get time or another set of eyes.

    • I think a lot of this code could be laid out a bit better (Although that goes for the whole site as well), while a rather small thing compared to actual bugs in the site the highly inconsistent use of spaces throughout the code makes some parts hard to understand. It should also be split up more into blocks by a blank line in-between blocks to help with readability.

    • Please register or sign in to reply
  • Laurence Sebastian Bowes Approved this merge request

    Approved this merge request

  • Isabel Jenkins Approved this merge request

    Approved this merge request

  • Isabel Jenkins mentioned in commit 2645f0b3

    mentioned in commit 2645f0b3

  • Isabel Jenkins Status changed to merged

    Status changed to merged

  • Please register or sign in to reply
    Loading