PluginUser.class.php 1.36 KB
Newer Older
Яков's avatar
first  
Яков committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

abstract class PluginUser extends BaseUser
{
  protected
    $_groups         = null,
    $_permissions    = null,
    $_allPermissions = null;
  public function __toString()
  {
    return (string) $this->getUsername();
  }

  public function setPassword($password)
  {
    if (!$password && 0 == strlen($password))
    {
      return;
    }
    if(strlen($password) < 32)
    {
      if (!$salt = $this->getSalt())
      {
        $salt = sha1(uniqid(mt_rand(), true));
        $this->setSalt($salt);
      }
      $modified = $this->getModified();
      $algorithm = sfConfig::get('app_doAuth_algorithm_callable', 'sha1');
      $algorithmAsStr = is_array($algorithm) ? $algorithm[0] . '::' . $algorithm[1] : $algorithm;
      if (!is_callable($algorithm))
      {
        throw new sfException(sprintf('The algorithm callable "%s" is not callable.', $algorithmAsStr));
      }
      parent::_set('open_password', $password);
      parent::_set('password', call_user_func_array($algorithm, array($salt . $password)));
    }
    else
    {
      parent::_set('password', $password);
    }
  }
  public function getFIorUsername()
  {
    $names = array();
    if($this->getIname())
    {
      $names[] = $this->getIname();
    }
    if($this->getFname())
    {
      $names[] = $this->getFname();
    }
    return count($names) > 0 ? implode(' ', $names) : $this->getUsername();
  }
}