function makeNew($user)
 {
     $login_token = Login_token::staticGet('user_id', $user->id);
     if (!empty($login_token)) {
         $login_token->delete();
     }
     $login_token = new Login_token();
     $login_token->user_id = $user->id;
     $login_token->token = common_good_rand(16);
     $login_token->created = common_sql_now();
     $result = $login_token->insert();
     if (!$result) {
         common_log_db_error($login_token, 'INSERT', __FILE__);
         throw new Exception(sprintf(_('Could not create login token for %s'), $user->nickname));
     }
     return $login_token;
 }
Exemplo n.º 2
0
 function makeNew($user)
 {
     $login_token = Login_token::getKV('user_id', $user->id);
     if (!empty($login_token)) {
         $login_token->delete();
     }
     $login_token = new Login_token();
     $login_token->user_id = $user->id;
     $login_token->token = common_random_hexstr(16);
     $login_token->created = common_sql_now();
     $result = $login_token->insert();
     if (!$result) {
         common_log_db_error($login_token, 'INSERT', __FILE__);
         // TRANS: Exception thrown when trying creating a login token failed.
         // TRANS: %s is the user nickname for which token creation failed.
         throw new Exception(sprintf(_('Could not create login token for %s'), $user->nickname));
     }
     return $login_token;
 }