1. PHP / Говнокод #7757

    +147

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    <?php
    /*
    	Виджет для формы логина
    */
    class UserLogin extends CWidget
    {
    	public function run()
    	{
                $model = new Login;
                if(!Yii::app()->user->isGuest)
                {
                    $this->render('loginOut', array('model'=>$model));
                } else {
                    $this->render('loginForm', array('model'=>$model));
                }
    	}
    }
    
    /**
     * модель логина
     */
    class Login extends CFormModel
    {
    	public $login;
    	public $pass;
    	public $rememberMe;
    
    	private $_identity;
    
    	public function rules()
    	{
                return array(
                    // username and password are required
                    array('login, pass', 'required', 'message'=>'поле {attribute} не может быть пустым'),
                    // rememberMe needs to be a boolean
                    array('rememberMe', 'boolean'),
                    // password needs to be authenticated
                    array('pass', 'authenticate'),
                );
    	}
    
    	/**
    	 * Declares attribute labels.
    	 */
    	public function attributeLabels()
    	{
                return array(
                    'login'=>'Логин',
                    'pass'=>'Пароль',
                    'rememberMe'=>'Запомнить',
                );
    	}
    
    	/**
    	 * Authenticates the password.
    	 * This is the 'authenticate' validator as declared in rules().
    	 */
    	public function authenticate($pass,$params)
    	{
                $this->_identity=new UserIdentity($this->login,$this->pass);
                if(!$this->_identity->authenticate())
                    $this->addError($pass, empty($params['message'])?'неправильный лоин или пароль':$params['message']);
    	}
    
    	/**
    	 * Logs in the user using the given username and password in the model.
    	 * @return boolean whether login is successful
    	 */
    	public function login()
    	{
                if($this->_identity===null)
                {
                    $this->_identity=new UserIdentity($this->login,$this->pass);
                    $this->_identity->authenticate();
                }
                if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
                {
                    $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
                    Yii::app()->user->login($this->_identity,$duration);
                    return true;
                } else {
                    return false;
                }
    	}
    }

    xyzdsnxyz, 03 Сентября 2011

    Комментарии (22)
  2. PHP / Говнокод #7756

    +149

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    <?php
    
    /**
     * Login class.
     * Login is the data structure for keeping
     * user login form data. It is used by the 'login' action of 'SiteController'.
     */
    class Login extends CFormModel
    {
    	public $login;
    	public $pass;
    	public $rememberMe;
    
    	private $_identity;
    
    	public function rules()
    	{
                return array(
                    // username and password are required
                    array('login, pass', 'required', 'message'=>'поле {attribute} не может быть пустым'),
                    // rememberMe needs to be a boolean
                    array('rememberMe', 'boolean'),
                    // password needs to be authenticated
                    array('pass', 'authenticate'),
                );
    	}
    
    	/**
    	 * Declares attribute labels.
    	 */
    	public function attributeLabels()
    	{
                return array(
                    'login'=>'Логин',
                    'pass'=>'Пароль',
                    'rememberMe'=>'Запомнить',
                );
    	}
    
    	/**
    	 * Authenticates the password.
    	 * This is the 'authenticate' validator as declared in rules().
    	 */
    	public function authenticate($pass,$params)
    	{
                $this->_identity=new UserIdentity($this->login,$this->pass);
                if(!$this->_identity->authenticate())
                    $this->addError($pass, empty($params['message'])?'неправильный лоин или пароль':$params['message']);
    	}
    
    	/**
    	 * Logs in the user using the given username and password in the model.
    	 * @return boolean whether login is successful
    	 */
    	public function login()
    	{
                if($this->_identity===null)
                {
                    $this->_identity=new UserIdentity($this->login,$this->pass);
                    $this->_identity->authenticate();
                }
                if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
                {
                    $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
                    Yii::app()->user->login($this->_identity,$duration);
                    return true;
                } else {
                    return false;
                }
    	}
    }

    модель логина

    xyzdsnxyz, 03 Сентября 2011

    Комментарии (2)
  3. Куча / Говнокод #7755

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    <select size="1" name="sex" id="sex" class="width_50">
                        <option value="0">Female</option>
                        <option value="2">Male</option>
    </select>

    тонко.

    jokz, 03 Сентября 2011

    Комментарии (49)
  4. JavaScript / Говнокод #7754

    +164

    1. 1
    layer = eval('document.getElementById("' + name + '").style');

    Зачееееем?

    jQuery, 02 Сентября 2011

    Комментарии (5)
  5. PHP / Говнокод #7753

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if ($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) {$browsus = htmlspecialchars(stripslashes($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']));} elseif($_SERVER['HTTP_USER_AGENT']) {$browsus=htmlspecialchars(stripslashes($_SERVER['HTTP_USER_AGENT']));} else {$browsus='Неопределен';}
    $browser=strtok($browsus,'(');
    $browser=strtok($browser,' ');
    $browser=substr($browser,0,22);
    $browser=preg_replace('#http://#i','', $browser);

    о как

    jQuery, 02 Сентября 2011

    Комментарии (2)
  6. JavaScript / Говнокод #7752

    +160

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    function addParam(iId)
    {   
        var sData = '';
    
        //Контрольная работа
        if (iId==1) 
            sData = '';
        // Реферат
        else if (iId==2) 
            sData = '';
        // Курсовая
        else if (iId==3) 
            sData = '';
        // Решение задач
        else if (iId==4) 
            sData = '';
        else {
            $('#addParam').hide().html('');
            return false;
        }
        
        $('#addParam').html('').append('<td colspan="2">'+sData+'</td>').show();
    }

    lot's of code, govnocode, govnocode, govnocode...

    kaspvar, 02 Сентября 2011

    Комментарии (3)
  7. JavaScript / Говнокод #7751

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $(".regions_table").find("tbody:nth-child(even) tr").attr("class","regions_blue")
    $(".regions_table").find("tbody:nth-child(odd) tr").attr("class","regions_grey")
    $(".regions_table tbody tr:nth-child(even)").addClass("_dark")
    $(".regions_table tr[class='regions_grey _dark']").attr("class", "regions_grey_dark")
    $(".regions_table tr[class='regions_blue _dark']").attr("class", "regions_blue_dark")

    Строчки 3-5 тру

    Connor, 02 Сентября 2011

    Комментарии (4)
  8. C++ / Говнокод #7750

    +170

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    assert( top( o-------o
                 |L       \
                 | L       \
                 |  o-------o
                 |  !       !
                 !  !       !
                 o  |       !
                  L |       !
                   L|       !
                    o-------o ) == ( o-------o
                                     |       !
                                     !       !
                                     o-------o ) );

    CPPGovno, 02 Сентября 2011

    Комментарии (20)
  9. Java / Говнокод #7749

    +78

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    getText( 
    							
    							
    		wifiStates[ 
    		           Settings.getLocationService( ) == null || !Settings.isCellConfigEnabled( ) ? LED_OFF
    							: Settings.isNetworkLocationEnabled( ) ? LED_ON
    									: LED_ERROR 
    				  ] ), Toast.LENGTH_SHORT )
    					.show( );

    Кусочек кода из приложения для андроида, которое придется поддерживать.... 0_0

    exeed, 02 Сентября 2011

    Комментарии (6)
  10. SQL / Говнокод #7748

    −116

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    --Если идентификатор аккаунта не передан возвращаем NULL
    IF @AccountID <= 0 OR @AccountID IS NULL RETURN 3;
    
    --Для администраторов всегда возвращаем NULL
    IF @Role = 'admin' OR @Role = 'super_admin' RETURN 3;

    Тело одной из хранимых процедур. Комментарии, видать, протухли.

    dante, 02 Сентября 2011

    Комментарии (1)