2011-12-17 3 views
1

은 법률이 같은 가져 오기 확인하는 것입니다. 이것은 다른 객체가 User라는 것입니다. 그래서 나는 fbuser ("페이스 북으로 로그인"을 통해 들어오는 페이스 북 사용자)와 구글 사용자와는 다른 webapp2_user와 같은이 모델을 사용자들에게 proabbly 이름을 짓게 될 것입니다. 그것은이 모델로 구글이나 페이스 북의 다른 계정을 연결 인정 이후 좋은 클래스를 보인다 이와 같은 가져 오기가 합법적입니까, 아니면 권장되지 않습니까?</p> <pre><code>from webapp2_extras.appengine.auth.models import User as webapp2.User </code></pre> <p>나는 그것이 기술적으로하더라도 webapp2.User 같은 객체를 참조하고 싶습니다 :

class User(object): 

    def get_id(self): 
     """Returns this user's unique ID, which can be an integer or string.""" 

    @classmethod 
    def get_by_auth_token(cls, user_id, token): 
     """Returns a user object based on a user ID and token. 

     :param user_id: 
      The user_id of the requesting user. 
     :param token: 
      The token string to be verified. 
     :returns: 
      A tuple ``(User, timestamp)``, with a user object and 
      the token timestamp, or ``(None, None)`` if both were not found. 
     """ 

    @classmethod 
    def get_by_auth_password(cls, auth_id, password): 
     """Returns a user object, validating password. 

     :param auth_id: 
      Authentication id. 
     :param password: 
      Password to be checked. 
     :returns: 
      A user object, if found and password matches. 
     :raises: 
      ``auth.InvalidAuthIdError`` or ``auth.InvalidPasswordError``. 
     """ 

    @classmethod 
    def create_auth_token(cls, user_id): 
     """Creates a new authorization token for a given user ID. 

     :param user_id: 
      User unique ID. 
     :returns: 
      A string with the authorization token. 
     """ 

    @classmethod 
    def delete_auth_token(cls, user_id, token): 
     """Deletes a given authorization token. 

     :param user_id: 
      User unique ID. 
     :param token: 
      A string with the authorization token. 
     """ 

답변

1

두 가지 모두 불법이며 권장하지 않습니다.

User 기본 클래스를 다른 응용 프로그램에서 사용하려면 해당 응용 프로그램에서 상속 받아 필요한 부분을 재정의해야합니다. 이런 방식으로 가져 오지 마십시오.

+0

내가 물어 본 것 이상으로 답변 해 주셔서 감사합니다. 기본 클래스는 webapp2 API에서 왔습니다. 암호 해시와 소금을 구현하지 않아도되는 큰 장점 인 암호 용 해시와 소금을 내장하고있는 것으로 보입니다. –

2
from webapp2_extras.appengine.auth.models import User as webapp2.User 

에 대한 답변이나 의견에 감사드립니다 유효하지 않은 구문은, 파이썬하지 않습니다 을 as webapp2.User에 넣으려면 대신 as webapp2_User을 사용해야합니다.