def user_confirm_email(request): """ this view takes three arguments from the URL aka request.matchdict - code - user name - user email and tries to match them to database entries. if matching is possible, - the email address in question is confirmed as validated - the database entry is changed to reflect this """ # values from URL/matchdict conf_code = request.matchdict['code'] user_name = request.matchdict['user_name'] user_email = request.matchdict['user_email'] #get matching user from db user = User.get_by_username(user_name) # check if the information in the matchdict makes sense # - user if isinstance(user, NoneType): #print "user is of type NoneType" return { 'result_msg': "Something didn't work. " "Please check whether you tried the right URL." } # - email if (user.email == user_email): #print "this one matched! " + str(user_email) if (user.email_is_confirmed): #print "confirmed already" return {'result_msg': "Your email address was confirmed already."} # - confirm code #print "checking confirmation code..." if (user.email_confirm_code == conf_code): #print "conf code " + str(conf_code) #print "user.conf code " + str(user.email_confirm_code) #print " -- found the right confirmation code in db" #print " -- set this email address as confirmed." user.email_is_confirmed = True return {'result_msg': "Thanks! Your email address has been confirmed."} # else return {'result_msg': "Verification has failed. Bummer!"}
def user_contract_de_username(request): """ get a PDF for the user to print out, sign and mail back special feature: username in filename """ try: username = request.matchdict['username'] user = User.get_by_username(username) assert(isinstance(user, User)) if DEBUG: # pragma: no cover print "about to generate pdf for user " + str(user.username) return generate_contract_de_fdf_pdf(user) except Exception, e: if DEBUG: # pragma: no cover print "something failed:" print e return HTTPFound(location=route_url('home', request))
try: num_users = dbsession.query(User).count() num_tracks = dbsession.query(Track).count() # num_tracks = 0 num_bands = dbsession.query(Band).count() # num_bands = 0 except ProgrammingError, pe: # ProgrammingError: (ProgrammingError) # SQLite objects created in a thread can only be used in that same # thread.The object was created in thread id -1333776384 # and this is thread id -1329573888 print "not a bug, a feature: logout first, please!" return HTTPFound(route_url('logout', request)) logged_in = authenticated_userid(request) user_id = User.get_by_username(logged_in) return dict( logged_in=logged_in, num_users=num_users, num_tracks=num_tracks, num_bands=num_bands, user_id=user_id ) # ######################################################### listen @view_config(route_name='listen', renderer='../templates/listen.pt', permission='view')
def _to_python(self, username, state): if not User.get_by_username(username): raise formencode.Invalid("That username does not exist", username, state) return username
def _to_python(self, username, state): if User.get_by_username(username): raise formencode.Invalid("That username already exists", username, state) return username