Пример #1
0
def promjeniEmail():
    result={
        "status" : False,
        "message" : "Neuspješna promjena emaila!"
    }
    
    fakultet = baseSession.query(Fakultet).filter(Fakultet.idFakulteta == session["user_data"]["idFakulteta"]).first()
    if fakultet != None:
        res = json.loads(Fakulteti.provjeriDostupnostEmaila(request.form['noviEmail'], False))
        if res["status"] == True:
            if fakultet.lozinka == hashlib.sha512((request.form['trenutnaLozinka']).encode()).hexdigest():
                fakultet.email = request.form['noviEmail']
                baseSession.add(fakultet)
                baseSession.commit()
                result["status"] = True
                result["message"] = "Email uspješno promjenjen!"
                
                try:
                    dnevnik = Dnevnik(session["user_data"]["idFakulteta"], "Fakultet", "Promjena emaila")
                    baseSession.add(dnevnik)
                    baseSession.commit()
                except (BaseException, KeyError):
                    baseSession.rollback()
                    pass
                
            else:
                result["message"] += " Pogrešna lozinka!"
        else:
            result["message"] += res["message"]
    return Response(json.dumps(result), mimetype='application/json; charset=UTF-8') 
Пример #2
0
def prijava():
    form = LoginForm(csrf_enabled = True)

    if request.method == 'POST':
        form.email = request.form['email']
        form.password = request.form['password']
        form.validate()

        if form.email == 'admin' and form.password == 'admin':
            session['user_data'] = {"email" : "admin"}
            return redirect('/admin')
        try:
            res = json.loads(Fakulteti.restPrijava(form.email, form.password))
            if res['status'] == True:
                return redirect('/app')
            else:
                flash('Neuspješna prijava! Pogrešan email ili lozinka ili korisnik ne postoji!')
        except ValueError:
            flash(('Neuspješna prijava! Pogrešan email ili lozinka ili korisnik ne postoji!').encode('utf-8'))
    return render_template('login.html', form = LoginForm(csrf_enabled = True))
Пример #3
0
def registracija():
    form = RegistrationForm(csrf_enabled = True)
    if request.method == 'POST':
        res = json.loads(Fakulteti.provjeriDostupnostEmaila(request.form['email'], False))
        if res['status'] == True:
            try:
                aKod = hashlib.sha224((request.form['email']+"o/6sfasSASD!#54!)w").encode()).hexdigest()
                noviFakultet = Fakultet(email=request.form['email'], lozinka = hashlib.sha512((request.form['password']).encode()).hexdigest(), \
                     aktiviran = False, blokiran = False, aktivacijskiKod=aKod)
                baseSession.add(noviFakultet)
                mail = Mail()
                msg = Message()
                msg.sender = ('Keglja inc. - StuFacJoint', '*****@*****.**')
                msg.subject = "Dobrodošli na StuFacJoint"
                msg.recipients = [request.form['email']]
                msg.body = 'Poveznica za aktivaciju: ' + url_for('index', _external=True) + 'rest/9f5a0e9de8ed801c983bf3019ca40c54f08b4a03/' + aKod
                msg.html = '''
                    <html>
                        <head>
                            <title> Potvrda elektroničke pošte </title>
                        </head>
                        <body>
                            <h1> Dobrodošli na StuFacJoint </h1>
                            <p> Kako bi koristili usluge molimo Vas da potvrdite adresu elektroničke pošte. </p>
                            <p> Aktivaciju možete izvršiti klikom na <a href='%s'>AKTIVIRAJ StuFacJoint</a> </p>
                        </body>
                    </html>
                ''' % (url_for('index', _external=True) + 'rest/9f5a0e9de8ed801c983bf3019ca40c54f08b4a03/' + aKod)
                mail.send(msg)

                baseSession.commit()
                return redirect('/login')
            except ValueError:
                baseSession.rollback()
                flash(("Greška kod registracije!").decode('utf-8'))
        else:
            flash((res['message']).decode('utf-8'))
    return render_template('registracija.html', form = form)
Пример #4
0
def odjava():
    Fakulteti.restOdjava()
    return redirect(url_for('index'))