Welcome Guest, Not a member yet? Register   Sign In
help on user authorization
#2

[eluser]Colin Williams[/eluser]
Well, right away it is clear that you are running two identical queries, something you should never have to do. Consider caching results in a property of your model. This means you'll always check your cache property first, then run the query if you don't find it there. You'll also need to remember to update your cache when the data is manipulated (per request only.)

Prototype:

Code:
class User extends Model {
  var $users = array();

  function get($uid)
  {
    if (!isset($this->users[$uid]))
    {
      // 1) Query the db: $user = $this->db->get() ...
      // 2) Add result to $this->users cache
    }
    else
    {
      // $user = $this->users[$uid]
    }
    return $user;
  {
}

Also, I see no need to run two checks to do the login. You could simply have an authenticate() method that returns false on the conditions a) there is no such user in the database, or b) the password for the user is wrong.


Messages In This Thread
help on user authorization - by El Forum - 07-18-2008, 08:55 PM
help on user authorization - by El Forum - 07-18-2008, 11:58 PM
help on user authorization - by El Forum - 07-19-2008, 02:47 AM
help on user authorization - by El Forum - 07-19-2008, 06:58 AM
help on user authorization - by El Forum - 07-19-2008, 07:41 AM
help on user authorization - by El Forum - 07-19-2008, 08:28 AM
help on user authorization - by El Forum - 06-02-2009, 04:55 AM
help on user authorization - by El Forum - 06-02-2009, 03:31 PM



Theme © iAndrew 2016 - Forum software by © MyBB