コード例 #1
0
ファイル: server.py プロジェクト: Lambdanaut/Drawrawr
def login():
  """Handles logging in to Drawrawr"""
  if request.method == 'POST':
    required_parameters = ["username","password"]
    if not util.all_in_list(required_parameters, request.form):
      return "0" #ERROR, A required form element wasn't found
    user_result = users_model.get_one({'lowername' : request.form['username'].lower() })
    if not user_result:
      return "2" # No username match
    if cryptography.encrypt_password(request.form['password'], True) != user_result['password']: 
      return "3" # No password match
    session['username'] = user_result['username']
    session['password'] = user_result['password']
    session.permanent = True
    # Add the user's IP to the front of the list of his IPs
    ip = user_result["ip"]
    try: ip.remove(request.remote_addr)
    except ValueError: pass
    ip.insert(0,request.remote_addr)
    users_model.update({"lowername": user_result['lowername']}, {"ip": ip})
    return "1"
コード例 #2
0
ファイル: server.py プロジェクト: Lambdanaut/Drawrawr
def signup(): 
  """Handles member signup requests"""
  # Error Handling
  required_parameters = ['username','password1','password2']
  if config.captcha: required_parameters += ['recaptcha_challenge_field','recaptcha_response_field']
  if config.beta_key: required_parameters += ['beta_code']
  if not util.all_in_list(required_parameters, request.form):
    return "0" #ERROR, A required form element wasn't found
  username_len = len(request.form['username'])
  if users_model.username_taken(request.form['username']) or username_len == 0 or username_len > 30:
    return "2" #ERROR, User doesn't exist or username is too small
  if request.form['password1'] != request.form['password2'] or not request.form['password1']:
    return "3" #ERROR, Passwords don't match
  if not 'tos_agree' in request.form:
    return "4" #ERROR, Terms of Service wasn't checked
  if config.captcha and not captcha.check(request.form['recaptcha_challenge_field'], request.form['recaptcha_response_field'],config.captcha_secret_key,request.remote_addr):
    return "5" #ERROR, Captcha Fail
  if config.beta_key:
    beta_key = beta_pass_model.check(request.form["beta_code"])
    if not beta_key:
      return "6" #ERROR, Beta Code Fail
  if g.logged_in_user:
    return "7" #ERROR, User is already logged in
  else: beta_key = None
  # Add the user to the database
  hashed = cryptography.encrypt_password(request.form['password1'], True)
  icon_filepath = os.path.join(config.icons_dir, request.form['username'].lower())
  storage.push("static/images/newby_icon.png", icon_filepath, mimetype="image/png")
  if not config.using_S3: shutil.copyfile("static/images/newby_icon.png", icon_filepath)
  users_model.insert({
    "username"    : request.form['username']
  , "lowername"   : request.form['username'].lower()
  , "password"    : hashed
  , "email"       : None #request.form['email']
  , "ip"          : [request.remote_addr]
  , "dob"         : None
  , "beta_key"    : beta_key
  , "beta_keys"   : config.starting_beta_keys
  , "date_joined" : datetime.datetime.today()
  , "show_ads"    : True
  , "layout"      : {
      # [CARDINAL LOCATION, ORDERING]
      # t == top; l == left; r == right; b == bottom; h == hidden
      "profile"   : ["t",0]
    , "gallery"   : ["l",0]
    , "watches"   : ["r",0]
    , "comments"  : ["b",0]
    , "nearby"    : ["r",1]
    , "journal"   : ["l",1]
    , "shout"     : ["h",0]
    , "friends"   : ["h",0]
    , "awards"    : ["h",0]
    , "shop"      : ["h",0]
    , "favorites" : ["h",0]
    , "tips"      : ["h",0]
    , "chars"     : ["h",0]
    , "playlist"  : ["h",0]
    }
  , "permissions" : {
      "delete_comments"    : True
    , "edit_art"           : True
    , "delete_art"         : True
    , "delete_journal"     : True
    , "ban_users"          : True
    , "make_props"         : True
    , "vote"               : True
    , "generate_beta_pass" : True
    , "crop_art"           : True
    }
  , "latitude"     : None
  , "longitude"    : None
  , "theme"        : "default"
  , "profile"      : ""
  , "code_profile" : ""
  , "page_views"   : 0
  , "watchers"     : []
  , "bground"      : None
  , "icon"         : "png"
  , "glued"        : 1
    # m == Male; f == Female; h == Hide Gender
  , "gender"       : "h"
  }) 
  session['username'] = request.form['username']
  session['password'] = hashed
  session.permanent = True
  return "1" #SUCCESS