def task_presenter(short_name, task_id): if (current_user.is_anonymous()): flash("Ooops! You are an anonymous user and will not get any credit " " for your contributions. <a href=\"" + url_for('account.signin', next=url_for('app.task_presenter',short_name=short_name,task_id=task_id)) \ + "\">Sign in now!</a>", "warning") app = App.query.filter_by(short_name=short_name)\ .first_or_404() task = db.session.query(model.Task).get(task_id) if (task.app_id == app.id): #return render_template('/applications/presenter.html', app = app) # Check if the user has submitted a task before if (current_user.is_anonymous()): if not request.remote_addr: remote_addr = "127.0.0.1" else: remote_addr = request.remote_addr tr = db.session.query(model.TaskRun)\ .filter(model.TaskRun.task_id == task_id)\ .filter(model.TaskRun.app_id == app.id)\ .filter(model.TaskRun.user_ip == remote_addr) else: tr = db.session.query(model.TaskRun)\ .filter(model.TaskRun.task_id == task_id)\ .filter(model.TaskRun.app_id == app.id)\ .filter(model.TaskRun.user_id == current_user.id) tr = tr.first() if (tr is None): return render_template('/applications/presenter.html', app=app) else: return render_template('/applications/task/done.html', app=app) else: return render_template('/applications/task/wrong.html', app=app)
def task_presenter(short_name, task_id): if (current_user.is_anonymous()): flash("Ooops! You are an anonymous user and will not get any credit " " for your contributions. <a href=\"" + url_for('account.signin', next=url_for('app.task_presenter',short_name=short_name,task_id=task_id)) \ + "\">Sign in now!</a>", "warning") app = App.query.filter_by(short_name=short_name)\ .first_or_404() task = db.session.query(model.Task).get(task_id) if (task.app_id == app.id): #return render_template('/applications/presenter.html', app = app) # Check if the user has submitted a task before if (current_user.is_anonymous()): if not request.remote_addr: remote_addr = "127.0.0.1" else: remote_addr = request.remote_addr tr = db.session.query(model.TaskRun)\ .filter(model.TaskRun.task_id == task_id)\ .filter(model.TaskRun.app_id == app.id)\ .filter(model.TaskRun.user_ip == remote_addr) else: tr = db.session.query(model.TaskRun)\ .filter(model.TaskRun.task_id == task_id)\ .filter(model.TaskRun.app_id == app.id)\ .filter(model.TaskRun.user_id == current_user.id) tr = tr.first() if (tr is None): return render_template('/applications/presenter.html', app=app) else: return render_template('/applications/task/done.html', app=app) else: return render_template('/applications/task/wrong.html', app=app)
def presenter(short_name): app = App.query.filter_by(short_name=short_name)\ .first_or_404() if app.info.get("tutorial"): if request.cookies.get(app.short_name + "tutorial") is None: if (current_user.is_anonymous()): flash("Ooops! You are an anonymous user and will not get any credit " " for your contributions. <a href=\"" + url_for('account.signin', next=url_for('app.tutorial',short_name=short_name)) \ + "\">Sign in now!</a>", "warning") resp = make_response( render_template('/applications/tutorial.html', app=app)) resp.set_cookie(app.short_name + 'tutorial', 'seen') return resp else: if (current_user.is_anonymous()): flash("Ooops! You are an anonymous user and will not get any credit " " for your contributions. <a href=\"" + url_for('account.signin', next=url_for('app.presenter',short_name=short_name)) \ + "\">Sign in now!</a>", "warning") return render_template('/applications/presenter.html', app=app) else: if (current_user.is_anonymous()): flash("Ooops! You are an anonymous user and will not get any credit " " for your contributions. <a href=\"" + url_for('account.signin', next=url_for('app.presenter',short_name=short_name)) \ + "\">Sign in now!</a>", "warning") return render_template('/applications/presenter.html', app=app)
def new_task(app_id): ####### ToDo: implement a Strategy Pattern here! Look: http://stackoverflow.com/questions/963965 # First check which SCHED scheme has to use this app app = model.Session.query(model.App).get(app_id) if (app.info.get('sched')): sched = app.info['sched'] else: sched = 'default' # Now get a task using the app sched if sched == 'default': # print "%s uses the %s scheduler" % (app.name,sched) if current_user.is_anonymous(): task = get_default_task(app_id,user_ip=request.remote_addr) else: task = get_default_task(app_id, user_id=current_user.id) if sched == 'random': # print "%s uses the %s scheduler" % (app.name,sched) if current_user.is_anonymous(): task = get_random_task(app_id,user_ip=request.remote_addr) else: task = get_random_task(app_id, user_id=current_user.id) if sched == 'incremental': # print "%s uses the %s scheduler" % (app.name,sched) if current_user.is_anonymous(): task = get_incremental_task(app_id,user_ip=request.remote_addr) else: task = get_incremental_task(app_id, user_id=current_user.id) # If there is a task for the user, return it if task: return Response(json.dumps(task.dictize()), mimetype="application/json") else: return Response(json.dumps({}), mimetype="application/json")
def task_presenter(short_name, task_id): if (current_user.is_anonymous()): flash("Ooops! You are an anonymous user and will not get any credit for your contributions. Sign in now!", "warning") app = model.Session.query(model.App).filter(model.App.short_name == short_name).first() task = model.Session.query(model.Task).get(task_id) if (task.app_id == app.id): #return render_template('/applications/presenter.html', app = app) # Check if the user has submitted a task before if (current_user.is_anonymous()): if not request.remote_addr: remote_addr="127.0.0.1" else: remote_addr = request.remote_addr tr = model.Session.query(model.TaskRun)\ .filter(model.TaskRun.task_id==task_id)\ .filter(model.TaskRun.app_id==app.id)\ .filter(model.TaskRun.user_ip==remote_addr) else: tr = model.Session.query(model.TaskRun)\ .filter(model.TaskRun.task_id==task_id)\ .filter(model.TaskRun.app_id==app.id)\ .filter(model.TaskRun.user_id==current_user.id) tr = tr.first() if (tr == None): return render_template('/applications/presenter.html', app = app) else: return render_template('/applications/task/done.html', app=app) else: return render_template('/applications/task/wrong.html', app=app)
def presenter(short_name): app = App.query.filter_by(short_name=short_name)\ .first_or_404() if app.info.get("tutorial"): if request.cookies.get(app.short_name + "tutorial") is None: if (current_user.is_anonymous()): flash("Ooops! You are an anonymous user and will not get any credit " " for your contributions. <a href=\"" + url_for('account.signin', next=url_for('app.tutorial',short_name=short_name)) \ + "\">Sign in now!</a>", "warning") resp = make_response(render_template('/applications/tutorial.html', app=app)) resp.set_cookie(app.short_name + 'tutorial', 'seen') return resp else: if (current_user.is_anonymous()): flash("Ooops! You are an anonymous user and will not get any credit " " for your contributions. <a href=\"" + url_for('account.signin', next=url_for('app.presenter',short_name=short_name)) \ + "\">Sign in now!</a>", "warning") return render_template('/applications/presenter.html', app=app) else: if (current_user.is_anonymous()): flash("Ooops! You are an anonymous user and will not get any credit " " for your contributions. <a href=\"" + url_for('account.signin', next=url_for('app.presenter',short_name=short_name)) \ + "\">Sign in now!</a>", "warning") return render_template('/applications/presenter.html', app=app)
def task_presenter(short_name, task_id): app = app_by_shortname(short_name) task = Task.query.filter_by(id=task_id).first_or_404() if current_user.is_anonymous(): if not app.allow_anonymous_contributors: msg = ("Oops! You have to sign in to participate in " "<strong>%s</strong>" "application" % app.name) flash(lazy_gettext(msg), 'warning') return redirect(url_for('account.signin', next=url_for('.presenter', short_name=app.short_name))) else: msg_1 = lazy_gettext( "Ooops! You are an anonymous user and will not " "get any credit" " for your contributions.") next_url = url_for( 'app.task_presenter', short_name=short_name, task_id=task_id) url = url_for( 'account.signin', next=next_url) flash(msg_1 + "<a href=\"" + url + "\">Sign in now!</a>", "warning") title = app_title(app, "Contribute") template_args = {"app": app, "title": title} def respond(tmpl): return render_template(tmpl, **template_args) if not (task.app_id == app.id): return respond('/applications/task/wrong.html') #return render_template('/applications/presenter.html', app = app) # Check if the user has submitted a task before tr_search = db.session.query(model.TaskRun)\ .filter(model.TaskRun.task_id == task_id)\ .filter(model.TaskRun.app_id == app.id) if current_user.is_anonymous(): remote_addr = request.remote_addr or "127.0.0.1" tr = tr_search.filter(model.TaskRun.user_ip == remote_addr) else: tr = tr_search.filter(model.TaskRun.user_id == current_user.id) tr_first = tr.first() if tr_first is None: return respond('/applications/presenter.html') else: return respond('/applications/task/done.html')
def task_presenter(short_name, task_id): app = app_by_shortname(short_name) task = Task.query.filter_by(id=task_id).first_or_404() if current_user.is_anonymous(): if not app.allow_anonymous_contributors: msg = ("Oops! You have to sign in to participate in " "<strong>%s</strong>" "application" % app.name) flash(lazy_gettext(msg), 'warning') return redirect(url_for('account.signin', next=url_for('.presenter', short_name=app.short_name))) else: msg_1 = lazy_gettext( "Ooops! You are an anonymous user and will not " "get any credit" " for your contributions.") next_url = url_for( 'app.task_presenter', short_name=short_name, task_id=task_id) url = url_for( 'account.signin', next=next_url) flash(msg_1 + "<a href=\"" + url + "\">Sign in now!</a>", "warning") title = app_title(app, "Contribute") template_args = {"app": app, "title": title} def respond(tmpl): return render_template(tmpl, **template_args) if not (task.app_id == app.id): return respond('/applications/task/wrong.html') #return render_template('/applications/presenter.html', app = app) # Check if the user has submitted a task before tr_search = db.session.query(model.TaskRun)\ .filter(model.TaskRun.task_id == task_id)\ .filter(model.TaskRun.app_id == app.id) if current_user.is_anonymous(): remote_addr = request.remote_addr or "127.0.0.1" tr = tr_search.filter(model.TaskRun.user_ip == remote_addr) else: tr = tr_search.filter(model.TaskRun.user_id == current_user.id) tr_first = tr.first() if tr_first is None: return respond('/applications/presenter.html') else: return respond('/applications/task/done.html')
def new_task(app_id): # Check if the request has an arg: if request.args.get('offset'): offset = int(request.args.get('offset')) else: offset = 0 user_id = None if current_user.is_anonymous() else current_user.id user_ip = request.remote_addr if current_user.is_anonymous() else None task = sched.new_task(app_id, user_id, user_ip, offset) # If there is a task for the user, return it if task: return Response(json.dumps(task.dictize()), mimetype="application/json") else: return Response(json.dumps({}), mimetype="application/json")
def presenter(short_name): app = app_by_shortname(short_name) title = app_title(app, "Contribute") template_args = {"app": app, "title": title} if not app.allow_anonymous_contributors and current_user.is_anonymous(): msg = "Oops! You have to sign in to participate in <strong>%s</strong> \ application" % app.name flash(lazy_gettext(msg), 'warning') return redirect(url_for('account.signin', next=url_for('.presenter', short_name=app.short_name))) msg = "Ooops! You are an anonymous user and will not \ get any credit for your contributions. Sign in \ now!" def respond(tmpl): if (current_user.is_anonymous()): msg_1 = lazy_gettext(msg) flash(msg_1, "warning") resp = make_response(render_template(tmpl, **template_args)) return resp if app.info.get("tutorial") and \ request.cookies.get(app.short_name + "tutorial") is None: resp = respond('/applications/tutorial.html') resp.set_cookie(app.short_name + 'tutorial', 'seen') return resp else: return respond('/applications/presenter.html')
def ctx_proc_userdata(): userdata = {} userdata['username'] = '******' if current_user.is_anonymous( ) else current_user.name userdata['user_is_authenticated'] = current_user.is_authenticated() userdata['user_is_admin'] = current_user.is_admin() return userdata
def register(): """Registers the user.""" form = RegisterForm(request.form) if not (current_user.is_anonymous()): flash("you are logined") return render_template("logout.html") if request.method == "POST" and form.validate_on_submit(): username = form.username.data password = form.password.data password2 = form.password2.data email = form.email.data if User.query.filter_by(username=username).first(): flash("The username is already taken") elif cmp(password, password2) != 0: flash("password mismatched") else: user = User(username, None, email) user.set_password(password) try: user.store_to_db() return render_template("account/registerok.html") except: flash("You were register failed, pls contact %s for help." % app.config["ADMIN"][1]) else: return render_template("account/register.html", form=form) return render_template("account/register.html", form=form)
def signin(): form = LoginForm(request.form, csrf_enabled=False) if request.method == 'POST' and form.validate(): password = form.password.data username = form.username.data user = model.User.by_name(username) if user and user.check_password(password): login_user(user, remember=True) flash("Welcome back %s" % user.fullname, 'success') return redirect(request.args.get("next") or url_for("home")) else: flash('Incorrect email/password', 'error') if request.method == 'POST' and not form.validate(): flash('Please correct the errors', 'error') auth = {'twitter': False} if current_user.is_anonymous(): # If Twitter is enabled in config, show the Twitter Sign in button if ('twitter' in current_app.blueprints): auth['twitter'] = True return render_template('account/signin.html', title="Sign in", form=form, auth=auth, next=request.args.get('next')) # Else use only the default system else: return render_template('account/signin.html', title="Sign in", form=form, auth=auth, next=request.args.get('next')) else: # User already signed in, so redirect to home page return redirect(url_for("home"))
def signin(): form = LoginForm(request.form) if request.method == 'POST' and form.validate(): password = form.password.data username = form.username.data user = model.User.by_name(username) if user and user.check_password(password): login_user(user, remember=True) flash("Welcome back %s" % user.fullname, 'success') return redirect(request.args.get("next") or url_for("home")) else: flash('Incorrect email/password', 'error') if request.method == 'POST' and not form.validate(): flash('Please correct the errors', 'error') auth = {'twitter': False, 'facebook': False, 'google': False} if current_user.is_anonymous(): # If Twitter is enabled in config, show the Twitter Sign in button if ('twitter' in current_app.blueprints): auth['twitter'] = True if ('facebook' in current_app.blueprints): auth['facebook'] = True if ('google' in current_app.blueprints): auth['google'] = True return render_template('account/signin.html', title="Sign in", form=form, auth=auth, next=request.args.get('next')) else: # User already signed in, so redirect to home page return redirect(url_for("home"))
def user_progress(app_id=None, short_name=None): """Return a JSON object with two fields regarding the tasks for the user: { 'done': 10, 'total: 100 } This will mean that the user has done a 10% of the available tasks for him """ if app_id or short_name: if short_name: app = db.session.query(model.App)\ .filter(model.App.short_name == short_name)\ .first() if app_id: app = db.session.query(model.App)\ .get(app_id) if app: if current_user.is_anonymous(): tr = db.session.query(model.TaskRun)\ .filter(model.TaskRun.app_id == app.id)\ .filter(model.TaskRun.user_ip == request.remote_addr)\ .all() else: tr = db.session.query(model.TaskRun)\ .filter(model.TaskRun.app_id == app.id)\ .filter(model.TaskRun.user_id == current_user.id)\ .all() # Return tmp = dict(done=len(tr), total=len(app.tasks)) return Response(json.dumps(tmp), mimetype="application/json") else: return abort(404) else: return abort(404)
def presenter(short_name): app = app_by_shortname(short_name) title = app_title(app, "Contribute") template_args = {"app": app, "title": title} if not app.allow_anonymous_contributors and current_user.is_anonymous(): msg = "Oops! You have to sign in to participate in <strong>%s</strong> \ application" % app.name flash(lazy_gettext(msg), 'warning') return redirect( url_for('account.signin', next=url_for('.presenter', short_name=app.short_name))) msg = "Ooops! You are an anonymous user and will not \ get any credit for your contributions. Sign in \ now!" def respond(tmpl): if (current_user.is_anonymous()): msg_1 = lazy_gettext(msg) flash(msg_1, "warning") resp = make_response(render_template(tmpl, **template_args)) return resp if app.info.get("tutorial") and \ request.cookies.get(app.short_name + "tutorial") is None: resp = respond('/applications/tutorial.html') resp.set_cookie(app.short_name + 'tutorial', 'seen') return resp else: return respond('/applications/presenter.html')
def signin(): form = LoginForm(request.form) if request.method == "POST" and form.validate(): password = form.password.data username = form.username.data user = model.User.by_name(username) if user and user.check_password(password): login_user(user, remember=True) flash("Welcome back %s" % user.fullname, "success") return redirect(request.args.get("next") or url_for("home")) else: flash("Incorrect email/password", "error") if request.method == "POST" and not form.validate(): flash("Please correct the errors", "error") auth = {"twitter": False, "facebook": False, "google": False} if current_user.is_anonymous(): # If Twitter is enabled in config, show the Twitter Sign in button if "twitter" in current_app.blueprints: auth["twitter"] = True if "facebook" in current_app.blueprints: auth["facebook"] = True if "google" in current_app.blueprints: auth["google"] = True return render_template( "account/signin.html", title="Sign in", form=form, auth=auth, next=request.args.get("next") ) else: # User already signed in, so redirect to home page return redirect(url_for("home"))
def start(): """Display friendly start page""" if not current_user.is_anonymous(): if VIMES.config['SINGLE_USER']: return display_index(current_user) else: return redirect('/%s' % current_user) return render_template('start.html')
def presenter(short_name): if (current_user.is_anonymous()): flash( "Ooops! You are an anonymous user and will not get any credit for your contributions. Sign in now!", "warning") app = model.Session.query( model.App).filter(model.App.short_name == short_name).first() return render_template('/applications/presenter.html', app=app)
def __call__(self, *args, **kwargs): fc = self.wrapped(*args, **kwargs) if fc is not True: if current_user.is_anonymous(): raise abort(403) else: raise abort(401) return fc
def update(taskrun): if not current_user.is_anonymous() and taskrun.user != None: if taskrun.user.id == current_user.id: return True else: return False else: return False
def __call__(self, *args, **kwargs): fc = self.wrapped(*args, **kwargs) if fc is not True: if current_user.is_anonymous(): raise abort(403) else: raise abort(401) return fc
def update(task): if not current_user.is_anonymous(): app = model.Session.query(model.App).filter_by(id=task.app_id).one() if app.owner_id == current_user.id: return True else: return False else: return False
def create(task=None): if not current_user.is_anonymous(): app = db.session.query(model.App).filter_by(id=task.app_id).one() if app.owner_id == current_user.id or current_user.admin is True: return True else: return False else: return False
def update(task): if not current_user.is_anonymous(): app = db.session.query(model.App).filter_by(id = task.app_id).one() if app.owner_id == current_user.id: return True else: return False else: return False
def update(taskrun): if current_user.is_anonymous(): return False else: # User authenticated if current_user.admin: return True else: if taskrun.user is not None and taskrun.user.id == current_user.id: return True else: return False
def logging_in(app): lm = LoginManager() lm.login_view = "login" lm.user_loader(get_user) lm.setup_app(app) app.preprocess_request() assert not current_user.is_authenticated() assert current_user.is_anonymous() with assert_fired(user_logged_in): login_user(notch) assert current_user.name == u"Notch" assert session["user_id"] == u"1"
def users(): if current_user.is_anonymous(): abort(401) users = bibserver.dao.Account.query(sort={'_id':{'order':'asc'}},size=1000000) if users['hits']['total'] != 0: accs = [bibserver.dao.Account.get(i['_source']['_id']) for i in users['hits']['hits']] # explicitly mapped to ensure no leakage of sensitive data. augment as necessary users = [{"collections":len(i.collections),"_id":i["_id"],"_created":i["_created"],"description":i["description"]} for i in accs] if util.request_wants_json(): resp = make_response( json.dumps(users, sort_keys=True, indent=4) ) resp.mimetype = "application/json" return resp else: return render_template('account/users.html',users=users)
def signup(): if not current_user.is_anonymous(): return abort(403) form = Signup_Form(username=request.args.get("username", None), email=request.args.get("email", None), next=request.args.get("next", None)) if form.validate_on_submit(): # add user (not activated) request_user_account(form.username.data, form.password.data, form.email.data) flash("Thanks for signing up! An Activation mail has been sent to you (%s) please come back..." % (form.email.data) ) return redirect( url_for('base.index') ) return render_template('accounts/signup.html', form=form)
def new_task(app_id): # TODO: implement a Strategy Pattern here! # Look: http://stackoverflow.com/questions/963965 # First check which SCHED scheme has to use this app app = db.session.query(model.App).get(app_id) if (app.info.get('sched')): sched = app.info['sched'] else: sched = 'default' # Now get a task using the app sched if sched == 'default': # print "%s uses the %s scheduler" % (app.name,sched) if current_user.is_anonymous(): task = get_default_task(app_id, user_ip=request.remote_addr) else: task = get_default_task(app_id, user_id=current_user.id) if sched == 'random': # print "%s uses the %s scheduler" % (app.name,sched) if current_user.is_anonymous(): task = get_random_task(app_id, user_ip=request.remote_addr) else: task = get_random_task(app_id, user_id=current_user.id) if sched == 'incremental': # print "%s uses the %s scheduler" % (app.name,sched) if current_user.is_anonymous(): task = get_incremental_task(app_id, user_ip=request.remote_addr) else: task = get_incremental_task(app_id, user_id=current_user.id) # If there is a task for the user, return it if task: return Response(json.dumps(task.dictize()), mimetype="application/json") else: return Response(json.dumps({}), mimetype="application/json")
def presenter(short_name): app = db.session.query(model.App)\ .filter(model.App.short_name == short_name).first() if (current_user.is_anonymous()): flash("Ooops! You are an anonymous user and will not get any credit " "for your contributions. Sign in now!", "warning") if app.info.get("tutorial"): if request.cookies.get(app.short_name + "tutorial") is None: resp = make_response(render_template('/applications/tutorial.html', app=app)) resp.set_cookie(app.short_name + 'tutorial', 'seen') return resp else: return render_template('/applications/presenter.html', app=app) else: return render_template('/applications/presenter.html', app=app)
def presenter(short_name): app = db.session.query(model.App)\ .filter(model.App.short_name == short_name).first() if (current_user.is_anonymous()): flash( "Ooops! You are an anonymous user and will not get any credit " "for your contributions. Sign in now!", "warning") if app.info.get("tutorial"): if request.cookies.get(app.short_name + "tutorial") is None: resp = make_response( render_template('/applications/tutorial.html', app=app)) resp.set_cookie(app.short_name + 'tutorial', 'seen') return resp else: return render_template('/applications/presenter.html', app=app) else: return render_template('/applications/presenter.html', app=app)
def signin(): form = LoginForm(request.form) if request.method == 'POST' and form.validate(): password = form.password.data email = form.email.data user = model.User.query.filter_by(email_addr=email).first() if user and user.check_password(password): login_user(user, remember=True) msg_1 = lazy_gettext("Welcome back") + " " + user.fullname flash(msg_1, 'success') return redirect(request.args.get("next") or url_for("home")) elif user: msg, method = get_user_signup_method(user) if method == 'local': msg = lazy_gettext("Ooops, Incorrect email/password") flash(msg, 'error') else: flash(msg, 'info') else: msg = lazy_gettext("Ooops, we didn't find you in the system, \ did you sign in?") flash(msg, 'info') if request.method == 'POST' and not form.validate(): flash(lazy_gettext('Please correct the errors'), 'error') auth = {'twitter': False, 'facebook': False, 'google': False} if current_user.is_anonymous(): # If Twitter is enabled in config, show the Twitter Sign in button if ('twitter' in current_app.blueprints): auth['twitter'] = True if ('facebook' in current_app.blueprints): auth['facebook'] = True if ('google' in current_app.blueprints): auth['google'] = True return render_template('account/signin.html', title="Sign in", form=form, auth=auth, next=request.args.get('next')) else: # User already signed in, so redirect to home page return redirect(url_for("home"))
def signin(): form = LoginForm(request.form) if request.method == 'POST' and form.validate(): password = form.password.data email = form.email.data user = model.User.query.filter_by(email_addr=email).first() if user and user.check_password(password): login_user(user, remember=True) msg_1 = lazy_gettext("Welcome back") + " " + user.fullname flash(msg_1, 'success') return redirect(request.args.get("next") or url_for("home")) elif user: msg, method = get_user_signup_method(user) if method == 'local': msg = lazy_gettext("Ooops, Incorrect email/password") flash(msg, 'error') else: flash(msg, 'info') else: msg = lazy_gettext("Ooops, we didn't find you in the system, \ did you sign in?") flash(msg, 'info') if request.method == 'POST' and not form.validate(): flash(lazy_gettext('Please correct the errors'), 'error') auth = {'twitter': False, 'facebook': False, 'google': False} if current_user.is_anonymous(): # If Twitter is enabled in config, show the Twitter Sign in button if ('twitter' in current_app.blueprints): auth['twitter'] = True if ('facebook' in current_app.blueprints): auth['facebook'] = True if ('google' in current_app.blueprints): auth['google'] = True return render_template('account/signin.html', title="Sign in", form=form, auth=auth, next=request.args.get('next')) else: # User already signed in, so redirect to home page return redirect(url_for("home"))
def profile(): print current_user if current_user.is_anonymous(): return redirect(url_for('create_profile')) form = ProfileForm(obj=current_user) if form.validate_on_submit(): existing_user = User.query.filter_by(name=request.form['name']).first() if existing_user: if existing_user.id != current_user.id: form.name.errors.append("Username already exists") else: existing_user.name = request.form['name'] existing_user.fullname = request.form['fullname'] if len(request.form['password']): existing_user.password = request.form['password'] print "updated user" flash("Your profile has been updated.") db.session.add(existing_user) db.session.commit() return render_template('profile.html', form=form, action="/profile/edit/")
def register(): form = RegisterForm() settings = Setting.all().order('-date_created')[0] if current_user.is_anonymous() != True: flash("You are already registered! Here's your profile.","error") return redirect(url_for('user_profile')) if form.validate_on_submit(): m = hashlib.sha224(form.password.data) all_users = SiteUser.all() emails = [x.email for x in all_users] if form.email.data in emails: flash('Error: Someone is already registered with that email. Please choose another one.') else: user = SiteUser(first_name = form.first_name.data, last_name = form.last_name.data, dislay_name = '%s %s' % (form.first_name.data, form.last_name.data), email = form.email.data, password = m.hexdigest(), registration_date = datetime.now(), role='registered-user', active=False) user.put() message = mail.EmailMessage(sender=settings.admin_email, subject='Confirmation of registration to %s' % settings.domain) message.to = form.email.data activate_user = SiteUser.gql("WHERE email = :1", form.email.data)[0] message.body = ''' This email serves to confirm that you are the owner of this email address. Please click the following activation link to confirm: %suser_activation/%s/ Thank you. ''' % (settings.domain,activate_user.key()) message.send() message = 'Registration was successful. Please click the activation link we sent to your email to activate your account.' return render_template('cms_blank.html', message=message) return render_template("cms_register.html", form=form)
def get_facebook_token(): if current_user.is_anonymous(): return session.get('oauth_token') else: return (current_user.info['facebook_token']['oauth_token'], '')
def update(app): if not current_user.is_anonymous() and (app.owner_id == current_user.id or current_user.admin is True): return True else: return False
def presenter(short_name): if (current_user.is_anonymous()): flash("Ooops! You are an anonymous user and will not get any credit for your contributions. Sign in now!", "warning") app = model.Session.query(model.App).filter(model.App.short_name == short_name).first() return render_template('/applications/presenter.html', app = app)
def get_twitter_token(): if current_user.is_anonymous(): return None else: return((current_user.info['twitter_token']['oauth_token'], current_user.info['twitter_token']['oauth_token_secret']))
def get_twitter_token(): if current_user.is_anonymous(): return None else: return ((current_user.info['twitter_token']['oauth_token'], current_user.info['twitter_token']['oauth_token_secret']))
def create(app=None): return not current_user.is_anonymous()
def update(app): if not current_user.is_anonymous() and app.owner_id == current_user.id: return True else: return False
def get_facebook_token(): if current_user.is_anonymous(): return session.get('oauth_token') else: return (current_user.info['facebook_token']['oauth_token'], '')
def _update_object(self, obj): if not current_user.is_anonymous(): obj.user = current_user else: obj.user_ip = request.remote_addr
def respond(tmpl): if (current_user.is_anonymous()): msg_1 = lazy_gettext(msg) flash(msg_1, "warning") resp = make_response(render_template(tmpl, **template_args)) return resp
def update(app): if not current_user.is_anonymous() and app.owner_id == current_user.id: return True else: return False
def create(app=None): return not current_user.is_anonymous()