Ejemplo n.º 1
0
def login(message):
	handler = message.get('handler')
	if handler is None:
		handler.redirect('/login.html', permanent = True)
		return None
	_ = handler.request.arguments
	connector = config.MysqlConnector()
	if connector is None:
		handler.redirect('/login.html', permanent = True)
		return None
	uname = _.get('username', None)
	if uname is None or len(uname) == 0:
		handler.redirect('/login.html', permanent = True)
		return None
	db_result = connector.select('u_user', '`uname` = "%s"' % uname[0])
	connector.close()
	if len(db_result) == 0:
		handler.redirect('/login.html', permanent = True)
		return None
	raw_password = db_result[0].get('passwd', None)
	if raw_password is None:
		handler.redirect('/login.html', permanent = True)
		return None
	passwd = _.get('password', None)
	if passwd is None or len(passwd) == 0:
		handler.redirect('/login.html', permanent = True)
		return None
	if raw_password <> passwd[0]:
		handler.redirect('/login.html', permanent = True)
		return None
	id_ = db_result[0].get('id', None)
	session.add(handler, id_)
	handler.redirect('/index.html', permanent = True)
	return None
Ejemplo n.º 2
0
    def on_post(self, request, response):
        params = json.loads(request.stream.read())
        random_number = INT(params.get("random_number"))

        with sql(commit=True) as session:
            stud = get_student_by_id(self.student_id, session)
            gid = stud.group_id
            group_size = len(get_group_members(gid, session))

            if group_size > 8:
                response.media = error("Your group is too large")
                return

            recepient = session.query(models.Student).filter_by(
                random_number=random_number).filter_by(sex=stud.sex).first()
            if recepient is None:
                response.media = error("Student not found")
                return

            invitation = session.query(models.Invitation).filter_by(
                student_id=recepient.student_id, group_id=gid).first()
            if invitation is not None: return
            invitation = models.Invitation(student_id=recepient.student_id,
                                           group_id=gid)
            session.add(invitation)
        response.media = {"success": True}
Ejemplo n.º 3
0
def file_post():
    file = request.files.get("file")
    if not file:
        data = {"message": "Could not find file data"}
        return Response(json.dumps(data), 422, mimetype="application/json")

    filename = secure_filename(file.filename)
    db_file = models.File(filename=filename)
    session.add(db_file)
    session.commit()
    file.save(upload_path(filename))

    data = db_file.as_dictionary()
    return Response(json.dumps(data), 201, mimetype="application/json")
Ejemplo n.º 4
0
def save_utilisateur(utilisateur: Utilisateur) -> bool:
    """
    Cette fonction enregistre un utilisateur
    """
    try:
        session.add(utilisateur)
        session.commit()
    except Exception as exception:
        print(exception)
        return False
    else:
        return True
    finally:
        session.flush()
Ejemplo n.º 5
0
def login():
    form = LoginForm()

    if form.validate_on_submit():
        username = form.username.data
        password = hash_string(form.password.data)

        user: User = User.query.filter_by(
            username=username, password=password).first()

        if user is None:
            return render_template("login.html", form=form, errors=form.errors, error="Usuario não encontrado")
        else:
            session.add(user.id)
            return redirect(url_for('store.index'))
    return render_template("login.html", form=form, errors=form.errors)
Ejemplo n.º 6
0
def singup():
    form = SingupForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        email = form.email.data

        if (check_existent_username(username)):
            return render_template("singup.html", form=form, errors=form.errors, error="nome de usuario ja existente")
        else:
            new_user = User(username, hash_string(password), email)

            db.session.add(new_user)
            db.session.commit()
            session.add(new_user.id)

        return redirect(url_for("store.index"))

    return render_template("singup.html", form=form, errors=form.errors)
Ejemplo n.º 7
0
 def process_item(self, item, spider):
     jokes = self.__get_jokes(item)
     if jokes:
         session.add(jokes)
         session.commit()
     return item
Ejemplo n.º 8
0
 def upsert(self, session=None):
     if not session:
         session = self.session
     session.add(self)
     session.commit()        
Ejemplo n.º 9
0
'''
Created on Jun 29, 2015

@author: lin
'''
from vod_orm import *
import session
import sqlalchemy.exc

session = session.getSession()
newUser = User(name='tom', id=23)
newVideo = Video(title = 'testvideo', id = 24)
user = session.query(User).filter(User.id == '23').one()
print '..'
print user
print '..'
newVideo.user = newUser.id
try:
    
    session.add(newUser)
    session.add(newVideo)
    res = session.query(Video).all()
    print res[0].title
    print newVideo
    session.commit()
except sqlalchemy.exc.IntegrityError as detail:
    print type(detail)