Exemplo n.º 1
0
    def authenticate(self, username=None, password=None):
        session = Session()
        user = session.query(User).filter_by(username=username).first()
        
        if user is not None:
            if not user.check_password(password):
                user = None     

        session.close()
        return user
Exemplo n.º 2
0
 def clean_username(self):
     # Since User.username is unique, this check is redundant,
     # but it sets a nicer error message than the ORM. See #13147.
     username = self.cleaned_data["username"]
     
     session = Session()
     c_users = session.query(User).filter_by(username=username).count()
     session.close()
     if c_users > 0:
         raise forms.ValidationError(self.error_messages['duplicate_username'])
     else:
         return username
Exemplo n.º 3
0
 def clean_email(self):
     """
     Validates that an active user exists with the given email address.
     """
     email = self.cleaned_data["email"]
     session = Session()
     self.users_cache = session.query(User).filter_by(email=email,
                                            is_active=True)
     session.close()
     if not len(self.users_cache):
         raise forms.ValidationError(self.error_messages['unknown'])
     if any((user.password == UNUSABLE_PASSWORD)
            for user in self.users_cache):
         raise forms.ValidationError(self.error_messages['unusable'])
     return email
Exemplo n.º 4
0
 def get_user(self, user_id):
     session = Session()
     user = session.query(User).get(user_id)
     session.close()
     return user 
Exemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     super(KeywordCheckConfigForm, self).__init__(*args, **kwargs)
     session = Session()
     self.fields['problem_meta_id'].choices = [('', '----------')] + [(pm.id, pm.title) for pm in session.query(ProblemMeta).all()]