Beispiel #1
0
def register_user():
  if request.method == 'POST':
    if mail_exist(request.form.get('email')):
      return 'mail exist'
    else:
      # Prepare user data to insert in db
      import crypt;
      salt = '$6$FIXEDS'
      pass_hash = crypt.crypt(request.form.get('password'), salt)
      user_row = User(nickname=request.form.get('username'),
                      email=request.form.get('email'), 
                      password=request.form.get('password'),
                      p_hash=pass_hash,
                      role=ROLE_USER,
                      register_date=datetime.now())
      app.logger.info('Registered user:\n'+
                      request.form.get('username')+'\n'+
                      request.form.get('email')+'\n'+
                      pass_hash+'\n') # debug
      db.session.add(user_row)
      try:
        db.session.commit()
      except IntegrityError: return "Try another e-mail."

      # Getting id of new user for project owner
      user_id = db.session.query(User.id).filter_by(email=request.form.get('email')).all()[0][0]
      app.logger.info('NEW USER ID:\t'+str(user_id)) # debug
      # Prepare empty project for user
      new_project = Project(name=u'Добро пожаловать',
                            status='Active',
                            owner=user_id)
      db.session.add(new_project)
      db.session.commit()

      # Getting Greet project id for assign task
      new_project_id = db.session.query(Project.id).filter_by(name=u'Добро пожаловать', owner=user_id).all()[0][0]
      # Creating user association to project
      new_assoc = Project_association(user_id=user_id, project_id=new_project_id)
      db.session.add(new_assoc)
      db.session.commit()

      # Setting Greet task
      task_row = Task(taskname=u"Это Ваша первая задача",
                      parent_id=0,
                      body=u"Вы можете создавать другие задачи в рамках проекта и делиться проектами с другими пользователями",
                      timestamp=datetime.now(),
                      user_id=user_id,
                      project_id=new_project_id,
                      status='Active',
                      depth=0)
      db.session.add(task_row)
      db.session.commit()

      return redirect(url_for('index'))

  if request.method == 'GET':
    return render_template('register.html', user=None)
Beispiel #2
0
def check_passwd(login, password):
  try:
    db_hash = get_hash_from_db(login)[0]
  except TypeError: return 0
  if db_hash: # exist
    salt_end = db_hash.rindex('$')
    salt = db_hash[:salt_end]
    import crypt;
    crypted_pass_hash = crypt.crypt(password, salt)
    if crypted_pass_hash == db_hash:
      return 1 # Passwords equal
    else:
      return 0 # Not equal
  else:
    return 0 # p_hash doesn't exist
Beispiel #3
0
def check_passwd(login, password):
    try:
        db_hash = get_hash_from_db(login)[0]
    except TypeError:
        return 0
    if db_hash:  # exist
        salt_end = db_hash.rindex('$')
        salt = db_hash[:salt_end]
        import crypt
        crypted_pass_hash = crypt.crypt(password, salt)
        if crypted_pass_hash == db_hash:
            return 1  # Passwords equal
        else:
            return 0  # Not equal
    else:
        return 0  # p_hash doesn't exist
Beispiel #4
0
def register_user():
    if request.method == 'POST':
        if mail_exist(request.form.get('email')):
            return 'mail exist'
        else:
            # Prepare user data to insert in db
            import crypt
            salt = '$6$FIXEDS'
            pass_hash = crypt.crypt(request.form.get('password'), salt)
            user_row = User(nickname=request.form.get('username'),
                            email=request.form.get('email'),
                            password=request.form.get('password'),
                            p_hash=pass_hash,
                            role=ROLE_USER,
                            register_date=datetime.now())
            app.logger.info(
                'Registered user:\n' + request.form.get('username') + '\n' +
                request.form.get('email') + '\n' + pass_hash + '\n')  # debug
            db.session.add(user_row)
            try:
                db.session.commit()
            except IntegrityError:
                return "Try another e-mail."

            # Getting id of new user for project owner
            user_id = db.session.query(
                User.id).filter_by(email=request.form.get('email')).all()[0][0]
            app.logger.info('NEW USER ID:\t' + str(user_id))  # debug
            # Prepare empty project for user
            new_project = Project(name=u'Добро пожаловать',
                                  status='Active',
                                  owner=user_id)
            db.session.add(new_project)
            db.session.commit()

            # Getting Greet project id for assign task
            new_project_id = db.session.query(Project.id).filter_by(
                name=u'Добро пожаловать', owner=user_id).all()[0][0]
            # Creating user association to project
            new_assoc = ProjectAssociation(user_id=user_id,
                                           project_id=new_project_id)
            db.session.add(new_assoc)
            db.session.commit()

            # Setting Greet task
            task_row = Task(
                taskname=u"Это Ваша первая задача",
                parent_id=0,
                body=
                u"Вы можете создавать другие задачи в рамках проекта и делиться проектами с другими пользователями",
                timestamp=datetime.now(),
                user_id=user_id,
                project_id=new_project_id,
                status='Active',
                depth=0)
            db.session.add(task_row)
            db.session.commit()

            return redirect(url_for('index'))

    if request.method == 'GET':
        return render_template('register.html', user=None)