Beispiel #1
0
    def update(self, **kwargs):
        """Update user fields
        """
        #TODO: update only the changed fields
        current = self.get_all_courses()
        incomplete = [ic.course for ic in filter(lambda c: c.completed == False, current)]
        completed  = [cc.course for cc in filter(lambda c: c.completed, current)]

        classpartition = {
            'iclasses': incomplete,
            'cclasses': completed
        }
        for t, l in classpartition.iteritems():
            if kwargs.has_key(t):
                self.recafooble_classes(l,
                    [ndb.Key('Course', k) for k in kwargs[t]], t)

        if kwargs.has_key('dob'):
            kwargs['dob'] = datetime.strptime(kwargs['dob'], '%m/%d/%Y')
        if kwargs.has_key('notify_on_msg'):
            kwargs['notify_on_msg'] = kwargs['notify_on_msg'] == 'on'

        for k, v in kwargs.iteritems():
            if hasattr(self, k):
                if k != 'password':
                    setattr(self, k, v)
                else:
                    setattr(self, k, bc.hashpw(kwargs['password'], bc.gensalt()))
        self.put()
Beispiel #2
0
    def update(self, **kwargs):
        """Update user fields
        """
        #TODO: update only the changed fields
        current = self.get_all_courses()
        incomplete = [
            ic.course for ic in filter(lambda c: c.completed == False, current)
        ]
        completed = [
            cc.course for cc in filter(lambda c: c.completed, current)
        ]

        classpartition = {'iclasses': incomplete, 'cclasses': completed}
        for t, l in classpartition.iteritems():
            if kwargs.has_key(t):
                self.recafooble_classes(
                    l, [ndb.Key('Course', k) for k in kwargs[t]], t)

        if kwargs.has_key('dob'):
            kwargs['dob'] = datetime.strptime(kwargs['dob'], '%m/%d/%Y')
        if kwargs.has_key('notify_on_msg'):
            kwargs['notify_on_msg'] = kwargs['notify_on_msg'] == 'on'

        for k, v in kwargs.iteritems():
            if hasattr(self, k):
                if k != 'password':
                    setattr(self, k, v)
                else:
                    setattr(self, k, bc.hashpw(kwargs['password'],
                                               bc.gensalt()))
        self.put()
Beispiel #3
0
 def save(username, email, password):
     if User.valid(username, email, password):
         password = bc.hashpw(password, bc.gensalt())
         # call to create and save log token is in signup controller
         user = User(username = username, password = password, email = email)
         user.put()
         return user
     return False
Beispiel #4
0
 def save(username, email, password):
     if User.valid(username, email, password):
         password = bc.hashpw(password, bc.gensalt())
         # call to create and save log token is in signup controller
         user = User(username = username, password = password, email = email)
         user.put()
         return user
     return False
Beispiel #5
0
    def save(cls, username, email, password):
        """Save a user object

        Returns:
         The saved User object
        """
        if cls.valid(username, email, password):
            password = bc.hashpw(password, bc.gensalt())
            # call to create and save log token is in signup controller
            user = cls(id = username, username = username, password = password, email = email)
            user.put()
            return user
        return False
Beispiel #6
0
    def save(cls, username, email, password):
        """Save a user object

        Returns:
         The saved User object
        """
        if cls.valid(username, email, password):
            password = bc.hashpw(password, bc.gensalt())
            # call to create and save log token is in signup controller
            user = cls(id = username, username = username, password = password, email = email)
            user.put()
            return user
        return False
Beispiel #7
0
 def create_and_save_log_token(user):
     log_token = bc.gensalt()
     user.log_token = bc.hashpw(log_token, bc.gensalt())
     user.put()
     return log_token
Beispiel #8
0
 def valid_log_token(username, log_token):
     user = User.get_user(username)
     return user and bc.hashpw(log_token, user.log_token) == user.log_token
Beispiel #9
0
 def valid_login(username, password):
     user = User.get_user(username)
     if user and bc.hashpw(password, user.password) == user.password:
         return Authentication.create_and_save_log_token(user)
 def create_and_save_log_token(user):
     log_token = bc.gensalt()
     user.log_token = bc.hashpw(log_token, bc.gensalt())
     user.put()
     return log_token
 def valid_log_token(username, log_token):
     user = User.get_user(username)
     return user and bc.hashpw(log_token, user.log_token) == user.log_token
 def valid_login(username, password):
     user = User.get_user(username)
     if user and bc.hashpw(password, user.password) == user.password:
         return Authentication.create_and_save_log_token(user) 
Beispiel #13
0
def check_password(user, password):
    error = {}
    if bc.hashpw(password, user.password) != user.password:
        error['error_password'] = '******'
        return False, error