Example #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
Example #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
Example #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
Example #4
0
 def save(self, commit=True):
     user = User()
     user.username = self.cleaned_data["username"]
     user.set_password(self.cleaned_data["password1"])
     session = Session()
     session.add(user)
     session.commit()
     session.close()
     return user
Example #5
0
def update_last_login(sender, user, **kwargs):
    """
    A signal receiver which updates the last_login date for
    the user logging in.
    """
    user.last_login = timezone.now()
    session = Session()
    session.merge(user)
    session.commit()
    session.close()
Example #6
0
 def save(self, commit=True):
     input_output_data = InputOutputData() 
     input_output_data.problem_meta_id = self.cleaned_data['problem_meta_id']       
     input_output_data.name = self.cleaned_data['name']   
     
     session = Session()
     session.add(input_output_data)
     session.commit()
     session.close()
     
     return  input_output_data
Example #7
0
 def save(self, commit=True):
     problem_meta = ProblemMeta()
     problem_meta.title = self.cleaned_data['title']
     problem_meta.judge_flow = self.cleaned_data['judge_flow']
     
     session = Session()
     session.add(problem_meta)
     session.commit()
     session.close()
     
     return problem_meta
Example #8
0
 def save(self, commit=True):
     output_check_config = OutputCheckConfig() 
     output_check_config.problem_meta_id = self.cleaned_data['problem_meta_id']       
     output_check_config.check_method = self.cleaned_data['check_method']   
     
     session = Session()
     session.add(output_check_config)
     session.commit()
     session.close()
     
     return  output_check_config
Example #9
0
 def save(self, commit=True):
     compile_config = CompileConfig() 
     compile_config.problem_meta_id = self.cleaned_data['problem_meta_id']       
     compile_config.code_type = self.cleaned_data['code_type']
     compile_config.config = self.cleaned_data['config']        
     
     session = Session()
     session.add(compile_config)
     session.commit()
     session.close()
     
     return  compile_config
Example #10
0
 def save(self, commit=True):
     keyword_check_config = KeywordCheckConfig()
     #keyword_check_config.problem_meta_id = int(self.cleaned_data['problem_meta_id'][0])
     keyword_check_config.problem_meta_id = self.cleaned_data['problem_meta_id']
     keyword_check_config.code_type = self.cleaned_data['code_type']                
     keyword_check_config.word = self.cleaned_data['word']
     
     session = Session()
     session.add(keyword_check_config)
     session.commit()
     session.close()
     
     return  keyword_check_config
Example #11
0
 def save(self, commit=True):
     compilable_code_generation_config = CompilableCodeGenerationConfig() 
     compilable_code_generation_config.problem_meta_id = self.cleaned_data['problem_meta_id']       
     compilable_code_generation_config.code_type_id = self.cleaned_data['code_type_id']
     compilable_code_generation_config.generation_method = self.cleaned_data['generation_method']  
     compilable_code_generation_config.requirment = self.cleaned_data['requirment']      
     
     session = Session()
     session.add(compilable_code_generation_config)
     session.commit()
     session.close()
     
     return  compilable_code_generation_config  
Example #12
0
 def setter(raw_password):
     self.set_password(raw_password)
     session = Session()
     session.merge(self)
     session.commit()
     session.close()
Example #13
0
 def get_user(self, user_id):
     session = Session()
     user = session.query(User).get(user_id)
     session.close()
     return user 
Example #14
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()]