def validate(self): self.rv = Form.validate(self) if not self.rv: return False tUser = User.getByUsername(self.login_username.data) if tUser == None: #not a valid username tUser = User.getByEmail( self.login_username.data ) #check if it is actaully an email address if tUser == None: self.login_username.errors.append( "The username you have entered does not exist") return False if tUser.is_oauth_user: self.login_username.errors.append( "The email you have entered is associated with a Facebook account, please login using Facebook." ) if not tUser.validatePassword(self.login_password.data): self.login_password.errors.append( "It seems you have entered an incorrect password") return False self.user = tUser return True
def validate(self): rv = Form.validate(self) self.rv = rv usernameExists = User.query.filter( User.username == self.reg_username.data).count() != 0 self.usernameExists = usernameExists if usernameExists: self.reg_username.errors.append( 'The username you have selected is already in use') return False emailExists = User.query.filter( User.email == self.reg_email.data).count() != 0 self.emailExists = emailExists if emailExists: self.reg_email.errors.append( 'The email address you have selected is already in use!' ) #perhaps we should let users make multiple accounts? return False if self.rv: self.user = User(self.reg_email.data, self.reg_username.data, plainTextPassword=self.reg_password.data) db.session.add(self.user) db.session.commit() return self.rv
def artwork(username,artworkUrlName=None): #TODO: better formatting of artworkName, %20 is horrible looking user = User.getByUsername(username) if user: artpiece = Artwork.query.filter(Artwork.user_id == user.id).filter(Artwork.url_name == artworkUrlName).first_or_404() return render_template('artpiece.html',artpiece=artpiece) else: app.logger.debug("Invalid artpiece page accessed:{username:%s, artworkName:%s}" % (username,artworkName)) return 'error, artwork does not exist' #TODO: Better error
def login(): app.logger.debug('%s login %s' % (request.method, request.form)) oauth_user = None fbUserObj = utils.getFacebookUserObj(request) if fbUserObj: oauth_user = User.getUserByFacebookUserObj(fbUserObj) if not oauth_user: try: oauth_user = User.createFromFacebookUserObj(fbUserObj) except AuthenticationException as ae: flash(ae.args[0]['message'], ) if oauth_user != None: login_user(oauth_user) if current_user.is_authenticated(): current_user.updateLastActive() return redirect(request.args.get('next', url_for('home'))) if request.method == "POST" and "login_username" in request.form: loginForm = LoginForm(request.form, csrf_enabled=False) if loginForm.validate(): login_user(loginForm.user) current_user.updateLastActive() return redirect(request.args.get( 'next', url_for('home'))) #check for nextUrl or default to Home else: for field, errors in loginForm.errors.iteritems(): for error in errors: flash(error, "login_error") elif request.method == "POST" and "reg_email" in request.form: registerForm = RegistrationForm(request.form, csrf_enabled=False) if registerForm.validate(): login_user(registerForm.user) current_user.updateLastActive() return redirect(url_for('home')) else: for field, errors in registerForm.errors.iteritems(): for error in errors: flash(error, "register_error") return render_template('login.html')
def validate(self): self.rv = Form.validate(self) if not self.rv: return False tUser = User.getByUsername(self.login_username.data) if tUser ==None: #not a valid username tUser = User.getByEmail(self.login_username.data) #check if it is actaully an email address if tUser == None: self.login_username.errors.append("The username you have entered does not exist") return False if tUser.is_oauth_user: self.login_username.errors.append("The email you have entered is associated with a Facebook account, please login using Facebook.") if not tUser.validatePassword(self.login_password.data): self.login_password.errors.append("It seems you have entered an incorrect password") return False self.user = tUser return True
def login(): app.logger.debug('%s login %s'% (request.method, request.form)) oauth_user = None fbUserObj = utils.getFacebookUserObj(request) if fbUserObj: oauth_user = User.getUserByFacebookUserObj(fbUserObj) if not oauth_user: try: oauth_user = User.createFromFacebookUserObj(fbUserObj) except AuthenticationException as ae: flash(ae.args[0]['message'],) if oauth_user != None: login_user(oauth_user) if current_user.is_authenticated(): current_user.updateLastActive() return redirect(request.args.get('next',url_for('home'))) if request.method == "POST" and "login_username" in request.form: loginForm = LoginForm(request.form, csrf_enabled=False) if loginForm.validate(): login_user(loginForm.user) current_user.updateLastActive() return redirect(request.args.get('next',url_for('home'))) #check for nextUrl or default to Home else: for field,errors in loginForm.errors.iteritems(): for error in errors: flash(error,"login_error") elif request.method == "POST" and "reg_email" in request.form: registerForm = RegistrationForm(request.form, csrf_enabled=False) if registerForm.validate(): login_user(registerForm.user) current_user.updateLastActive() return redirect(url_for('home')) else: for field,errors in registerForm.errors.iteritems(): for error in errors: flash(error,"register_error") return render_template('login.html')
def artists(username=None): if username: #browse directly to a user's artist page user = User.getByUsername(username) if user: return render_template('artist.html', artist=user) else: #general, view all artists page app.logger.debug("Invalid artist's page accessed:{%s}" % username) return 'error, artist does not exist!' #TODO: Better error else: artists = User.query.filter(User.has_image == True).all() return render_template('artists.html', artists=artists)
def artists(username=None): if username: #browse directly to a user's artist page user = User.getByUsername(username) if user: return render_template('artist.html',artist=user) else: #general, view all artists page app.logger.debug("Invalid artist's page accessed:{%s}" % username) return 'error, artist does not exist!' #TODO: Better error else: artists = User.query.filter(User.has_image==True).all() return render_template('artists.html',artists=artists)
def artwork( username, artworkUrlName=None ): #TODO: better formatting of artworkName, %20 is horrible looking user = User.getByUsername(username) if user: artpiece = Artwork.query.filter(Artwork.user_id == user.id).filter( Artwork.url_name == artworkUrlName).first_or_404() return render_template('artpiece.html', artpiece=artpiece) else: app.logger.debug( "Invalid artpiece page accessed:{username:%s, artworkName:%s}" % (username, artworkName)) return 'error, artwork does not exist' #TODO: Better error
def test_create(self): dbUser = User.query.filter(User.email == '*****@*****.**').first() if dbUser: #cleanup old test db.session.delete(dbUser) db.session.commit() user = User('*****@*****.**', 'joebloe', plainTextPassword='******') db.session.add(user) db.session.commit() dbUser = User.query.filter(User.email == '*****@*****.**').first() assert dbUser assert dbUser.validatePassword('secret') assert not dbUser.validatePassword('notTheSecret') db.session.delete(dbUser) db.session.commit() dbUser = User.query.filter(User.email == '*****@*****.**').first() assert dbUser == None
def load_user(id): return User.getById(id)