Пример #1
0
def get_bootstrap_data():
    authenticated = current_user.is_authenticated()

    #check if user is ucla verified
    ucla_circle = Circle.by_name("ucla")
    if authenticated and ucla_circle:
        if UserCircleAuth.by_user_circle_not_temp(current_user, ucla_circle):
            ucla_verified = True
        else:
            ucla_verified = False
    else:
        ucla_verified = False

    data = {
        'authenticated': authenticated,
        'categories': [{
            'name': i
        } for i in CATEGORIES],
        'ucla_verified': ucla_verified
    }

    if authenticated:
        data['user'] = current_user.to_json()

    return data
Пример #2
0
def login():
    """ POST only operation. check login form. Log user in """
    if current_user.is_authenticated():
        return Response.make_success_resp(msg="You are already logged in")

    form = LoginForm()
    if form.validate_on_submit():
        user, authenticated = User.authenticate(form.login.data,
                                                form.password.data)
        if user:
            if authenticated:
                login_user(user, remember=form.remember_me.data)
                return Response.make_data_resp(
                    data=current_user.to_json(),
                    msg="You have successfully logged in")
            else:
                return Response.make_error_resp(
                    msg="Invalid username or password",
                    type="Wrong Authentication",
                    code=422)
        else:
            return Response.make_error_resp(msg="Username does not exist",
                                            type="Wrong Authentication",
                                            code=422)

    return Response.make_form_error_resp(form=form)
Пример #3
0
def index(path):
    if path not in ['index', 'login', 'auth', 'privacy', 'terms']:
        if not current_user.is_authenticated():
            return current_app.login_manager.unauthorized()

    if current_user.is_anonymous():
        user_json = json.dumps({'name': 'Anonymous'})
    else:
        user_json = current_user.to_json(for_public=True)

    return render_template('index.html', user_json=user_json)
Пример #4
0
def index(path):
  if path not in ['index', 'login', 'auth']:
    if not current_user.is_authenticated():
      return current_app.login_manager.unauthorized()

  if current_user.is_anonymous():
    user_json = json.dumps({
      'name': 'Anonymous'
    })
  else:
    user_json = current_user.to_json(for_public=True)

  return render_template('index.html', user_json=user_json)
Пример #5
0
def fb_login():
   '''
      uses the fb coookie to login.
   '''
   try:
      user , error = authenticate_user_from_cookie(request.cookies)

      if error:
         return Response.make_error_resp(msg=error['msg'], code=error['code'])

      login_user(user)
   except Exception as e:
      return Response.make_exception_resp(exception=e)
   return Response.make_data_resp(data=current_user.to_json(), msg="You have successfully logged in")
Пример #6
0
def fb_app_login():
   '''
      uses the fb id to login.
   '''
   try:
      user, error = authenticate_user_from_fid(request.form.get('uid'))

      if error:
         return Response.make_error_resp(msg=error['msg'], code=error['code'])

      login_user(user, remember=True)
   except Exception as e:
      return Response.make_exception_resp(exception=e)

   return Response.make_data_resp(data=current_user.to_json(), msg="You have successfully logged in")
Пример #7
0
def update_settings():
   form = SettingsForm()
   if form.validate_on_submit():
      user = current_user
      try:
         user.first_name = form.first_name.data
         user.last_name = form.last_name.data
         settings = current_user.user_settings
         form.populate_obj(settings)
         settings.sex_code = form.sex_code.data;
         user.settings = settings
         db.session.commit()
      except Exception as e:
         return Response.make_exception_resp(exception=e)

      return Response.make_data_resp(data=current_user.to_json(), msg="You have successfully updated your settings!")
   return Response.make_form_error_resp(form=form)
Пример #8
0
def update_settings():
    form = SettingsForm()
    if form.validate_on_submit():
        user = current_user
        try:
            user.first_name = form.first_name.data
            user.last_name = form.last_name.data
            settings = current_user.user_settings
            form.populate_obj(settings)
            settings.sex_code = form.sex_code.data
            user.settings = settings
            db.session.commit()
        except Exception as e:
            return Response.make_exception_resp(exception=e)

        return Response.make_data_resp(
            data=current_user.to_json(),
            msg="You have successfully updated your settings!")
    return Response.make_form_error_resp(form=form)
Пример #9
0
def login():
    """ POST only operation. check login form. Log user in """
    if current_user.is_authenticated():
        return Response.make_success_resp(msg="You are already logged in")

    form = LoginForm()
    if form.validate_on_submit():
        user, authenticated = User.authenticate(form.login.data, form.password.data)
        if user:
            if authenticated:
                login_user(user, remember=form.remember_me.data)
                return Response.make_data_resp(data=current_user.to_json(), msg="You have successfully logged in")
            else:
                return Response.make_error_resp(
                    msg="Invalid username or password", type="Wrong Authentication", code=422
                )
        else:
            return Response.make_error_resp(msg="Username does not exist", type="Wrong Authentication", code=422)

    return Response.make_form_error_resp(form=form)
Пример #10
0
def get_bootstrap_data():
   authenticated = current_user.is_authenticated()

   #check if user is ucla verified
   ucla_circle = Circle.by_name("ucla")
   if authenticated and ucla_circle:
      if UserCircleAuth.by_user_circle_not_temp(current_user, ucla_circle):
         ucla_verified = True
      else:
         ucla_verified = False
   else:
      ucla_verified = False
      
   data = {
      'authenticated': authenticated,
      'categories' : [{'name': i} for i in CATEGORIES],
      'ucla_verified': ucla_verified
   }

   if authenticated:
      data['user'] = current_user.to_json()
      
   return data
   
Пример #11
0
def index(path):
    return render_template('index.html',
                           user_json=current_user.to_json(for_public=True))
Пример #12
0
@login_required

def verify_auth():  
   return Response.make_data_resp(data=current_user.to_json())

@auth.route('/login', methods=['POST'])
def login():
   if current_user.is_authenticated():
  return Response.make_success_resp(msg="You are already logged in")
  
   form = LoginForm()
   if form.validate_on_submit():
  user, authenticated = User.authenticate(form.login.data,
  form.password.data)
  if user :

  if authenticated:
    login_user(user, remember=form.remember_me.data)
  
    return Response.make_data_resp(data=current_user.to_json(), msg="You have successfully logged in")
 
 else:
    
    return Response.make_error_resp(msg="Invalid username or password", type="Wrong Authentication", code=422)

 else:
 
    return Response.make_error_resp(msg="Username does not exist", type="Wrong Authentication", code=422)

   return Response.make_form_error_resp(form=form)
Пример #13
0
def verify_auth():
    return Response.make_data_resp(data=current_user.to_json())
Пример #14
0
def verify_auth():
    '''Returns an HTTP 200 response and the user representation if user is logged in; returns a 401 status code and an error message if not.'''
    return Response.make_data_resp(data=current_user.to_json())
Пример #15
0
def get_settings():
    '''Return settings for the logged in user'''
    return Response.make_data_resp(data=current_user.to_json())
Пример #16
0
 def get(self):
     if current_user.is_anonymous():
         return { 'error': 'no_user' }
     else:
         return json.loads(current_user.to_json())
Пример #17
0
 def get(self):
     if current_user.is_anonymous():
         return {'error': 'no_user'}
     else:
         return json.loads(current_user.to_json())
Пример #18
0
def get_settings():
   '''Return settings for the logged in user'''
   return Response.make_data_resp(data=current_user.to_json())
Пример #19
0
def verify_auth():
    return Response.make_data_resp(data=current_user.to_json())
Пример #20
0
def index():
    return render_template('index.html',
        user_json=current_user.to_json(for_public=True))
Пример #21
0
def verify_auth():  
   '''Returns an HTTP 200 response and the user representation if user is logged in; returns a 401 status code and an error message if not.'''
   return Response.make_data_resp(data=current_user.to_json())