Exemplo n.º 1
0
def create_user():
    print('in create user')
    if g.user is not None or 'openid' not in session:
        return redirect(url_for('portal_user.index'))
    if request.method == 'POST':
        print('in post')
        email = request.form['email']
        if '@' not in email:
            flash(u'Error: you have to enter a valid email address')
        else:
            flash(u'Profile successfully created')
            db_session.add(User(email, session['openid']))
            db_session.commit()
            return redirect(oid.get_next_url())
    elif request.method == 'GET':
        print('in get')
        email = request.args.get('email', None)
        if '@' not in email:
            flash(u'Error: you have to enter a valid email address')
        else:
            flash(u'Profile successfully created')
            db_session.add(User(email, session['openid']))
            db_session.commit()
            # The index has a script that closes popup when logged in
            #return redirect(oid.get_next_url())
            return redirect(url_for('portal_user.index'))
    print('returning')
    return redirect(url_for('portal_user.index'))
Exemplo n.º 2
0
def create_user():
   print('in create user')
   if g.user is not None or 'openid' not in session:
      return redirect(url_for('portal_user.index'))
   if request.method == 'POST':
      print ('in post')
      email = request.form['email']
      if '@' not in email:
         flash(u'Error: you have to enter a valid email address')
      else:
         flash(u'Profile successfully created')
         db_session.add(User(email, session['openid']))
         db_session.commit()
         return redirect(oid.get_next_url())
   elif request.method == 'GET':
      print('in get')
      email = request.args.get('email', None)
      if '@' not in email:
         flash(u'Error: you have to enter a valid email address')
      else:
         flash(u'Profile successfully created')
         db_session.add(User(email, session['openid']))
         db_session.commit()
         # The index has a script that closes popup when logged in
         #return redirect(oid.get_next_url()) 
         return redirect(url_for('portal_user.index'))
   print('returning')
   return redirect(url_for('portal_user.index'))
Exemplo n.º 3
0
def create_or_login(resp):
   print('in create or login')
   session['openid'] = resp.identity_url
   user = User.query.filter_by(openid=resp.identity_url).first()
   if user is not None:
      flash(u'Successfully signed in')
      g.user = user
      return redirect(url_for('portal_user.index'))
   return redirect(url_for('portal_user.create_user', next=oid.get_next_url(),
                           email=resp.email))
Exemplo n.º 4
0
def create_or_login(resp):
    print('in create or login')
    session['openid'] = resp.identity_url
    user = User.query.filter_by(openid=resp.identity_url).first()
    if user is not None:
        flash(u'Successfully signed in')
        g.user = user
        return redirect(url_for('portal_user.index'))
    return redirect(
        url_for('portal_user.create_user',
                next=oid.get_next_url(),
                email=resp.email))
Exemplo n.º 5
0
def create_or_login(resp):
   generic_identity = resp.identity_url
   nickname = resp.nickname
   user_identity = generic_identity + '?id=' + hashlib.md5(nickname).hexdigest()
   session['openid'] = user_identity
   user = User.query.filter_by(openid=user_identity).first()

   if user is not None:
       g.user = user
       return redirect(url_for('portal_user.index'))
   group_extension = resp.extensions[GroupExtension.ns_alias]
   sreg_extension = resp.extensions[SRegResponse.ns_alias]
   return redirect(url_for('portal_user.create_user', next=oid.get_next_url(),
                           email=resp.email, groups=group_extension[GROUPS_KEY],
                           username=sreg_extension['nickname'],
                           full_name=sreg_extension['fullname']))
Exemplo n.º 6
0
def create_user():
   if g.user is not None or 'openid' not in session:
      raise ValueError('should never come here')
   if request.method == 'POST':
      print ('in post')
      email = request.form['email']
      group_names = request.form['groups'].split()
      username = request.form['username'].split()
      full_name = request.args.get('full_name', None)
      add_user_to_db(email, username, full_name, group_names)
      db_session.commit()
      print('Profile successfully created')
      return redirect(oid.get_next_url())
   elif request.method == 'GET':
      print('in get')
      email = request.args.get('email', None)
      group_names = request.args.get('groups', None).split()
      username = request.args.get('username', None)
      full_name = request.args.get('full_name', None)
      add_user_to_db(email, username, full_name, group_names)
      db_session.commit()
      print('Profile successfully created')
      return redirect(url_for('portal_user.index'))
   return redirect(url_for('portal_user.index'))