Beispiel #1
0
 def get(self):
     data = request.get_json()
     mail = data["mail"]
     user = UserModel.find_by_mail(mail)
     if user is None:
         return "does not exist"
     users = select_all()
     a = []
     if users:
         k = []
         for i in users:
             if i.ordine is not None:
                 k.append(i)
         newlist = sorted(k, key=lambda x: x.ordine)
         for i in newlist:
             a.append(i.username)
         return a
         c = ""
         if a:
             for i in a:
                 if i:
                     c = c + i + ","
             d = c[:-1]
             return {"name": d}, 200
     return {"name": ""}
Beispiel #2
0
 def get(self):
     mail = request.args.get('mail')
     user = UserModel.find_by_mail(mail)
     if user:
         users = select_all()
         a = []
         if users:
             b = []
             for i in users:
                 if i.ordine is not None:
                     b.append(i)
             newlist = sorted(b, key=lambda x: x.ordine)
             for i in newlist:
                 if i.ordine != None:
                     a.append(i)
             c = []
             for i in a:
                 if i.id == user.id:
                     p = 1
                 else:
                     p = 0
                 b = {
                     "username": i.username,
                     "conteggio": i.conteggio,
                     "isYou": p,
                     "mail": i.mail
                 }
                 c.append(b)
             return c
Beispiel #3
0
    def post(self):
        data = request.get_json()
        mail = data["mail"]
        user = UserModel.find_by_mail(mail)
        if user is None:
            return "does not exist", 500

        if user.ordine:
            return "already in list", 402
        users = class_users(user.classe_id)
        if users:
            ids = []
            for i in users:
                if i.ordine is not None:
                    ids.append(i.ordine)
            if ids:
                top = max(ids)
                ordine1 = top + 1
            else:
                ordine1 = 1
        else:
            ordine1 = 1
        user.ordine = ordine1

        user.save_to_db()
        return {"message": "user added to list"}, 200
Beispiel #4
0
    def post(self):
        mail=request.args.get('mail')
        username=request.args.get('username')
        password=request.args.get('password')
        phone=request.args.get('phoneNumber')
        user=UserModel.find_by_mail(mail)
        if user:
            if user.confirmed==True:
                return "mail already taken", 413
            epsw=password.encode('utf-8')
            hashed_password = hashlib.sha512(epsw).hexdigest()
            user.username=username
            user.password=hashed_password
            user.phone_number=phone
            user.creation_date=time.time()
            user.password_change=time.time()
            user.save_to_db()
        else:
            now = time.time()
            epsw=password.encode('utf-8')
            hashed_password = hashlib.sha512(epsw).hexdigest()
            user=UserModel(mail, phone, username, hashed_password)
            user.save_to_db()


        return user.username
        sendmail(mail, username)

        return "user created, to be confirmed", 200
Beispiel #5
0
 def post(self):
     mail = request.args.get('mail')
     username = request.args.get('username')
     user = UserModel.find_by_mail(mail)
     if user:
         user.username = username
         user.save_to_db()
         return {"message": "username changed successfully"}, 200
     return {"message": "user does not exist"}, 500
Beispiel #6
0
 def get(self):
     data = request.get_json()
     mail = data[0]
     user = UserModel.find_by_mail(mail)
     if user:
         classe = find_by_id(user.classe_id)
         if classe:
             return classe.tag
         return "user not in a class"
     return "user does not exist"
Beispiel #7
0
 def delete(self):
     mail = request.args.get('mail')
     user = UserModel.find_by_mail(mail)
     if user:
         if user.classe_id:
             user.classe_id = None
             user.save_to_db()
             return "user removed", 200
         return "user not in a class", 500
     return {"message": "user does not exist"}, 500
Beispiel #8
0
    def post(self):
        data = request.get_json()
        mail = data["mail"]
        username = data["username"]
        password = data["password"]
        user = UserModel.find_by_mail(mail)
        if user:
            if user.confermato == True:
                return "mail already taken", 400
            epsw = password.encode('utf-8')
            hashed_password = hashlib.sha512(epsw).hexdigest()
            user.password = hashed_password
            user.username = username
            user.save_to_db()
            return "user modified"
        now = datetime.datetime.now()
        epsw = password.encode('utf-8')
        hashed_password = hashlib.sha512(epsw).hexdigest()
        user = UserModel(None, mail, username, None, None, None, 0, False, 0)
        user.password = hashed_password

        user.save_to_db()
        s = URLSafeTimedSerializer("password1")
        token = s.dumps(mail, salt="emailconfirm")
        #link="http://127.0.0.1:5000/confirm/"+token
        link = "https://seconda.herokuapp.com/confirm/" + token
        subject = "Conferma la tua mail su WaitingList"

        text = """

Ciao {}!
Grazie per esserti registrato.
Clicca il link qui sotto per completare la registrazione.


{}

Se non hai richiesto un account non preoccuparti, qualcuno si sara' confuso.

Saluti,

il Team WaitingList



         """.format(username, link)
        message = 'Subject: {}\n\n{}'.format(subject, text)
        server = smtplib.SMTP('smtp.gmail.com', 587)
        server.ehlo()
        server.starttls()

        server.login("*****@*****.**", "smartmates1")
        server.sendmail("smartmates2018gmail.com", mail, message)

        return {"message": "user created, to be confirmed"}, 200
Beispiel #9
0
 def post(self):
     mail = request.args.get('mail')
     classe = request.args.get('class')
     user = UserModel.find_by_mail(mail)
     if user:
         tag = randomtag()
         class_to_add = ClassModel(None, classe, tag, user.id)
         class_to_add.save_to_db()
         class_added = ClassModel.find_by_tag(tag)
         return {"tag": tag}
     return {"message": "user does not exist"}, 400
Beispiel #10
0
    def delete(self):
        mail = request.args.get('mail')
        user = UserModel.find_by_mail(mail)
        if user:
            if user.ordine is not None:
                user.ordine = None

                user.save_to_db()
                return {"message": "deleted"}, 200
            return "not in list"
        return {"message": "user does not exist"}, 500
Beispiel #11
0
 def post(self):
     data = request.get_json()
     mail = data["mail"]
     admin = data["admin"]
     password = data["password"]
     if (admin == "matteo" and password == "matteo"):
         user = UserModel.find_by_mail(mail)
         if user:
             user.delete_from_db()
             return "done", 200
         return "ops", 405
     return "pesce", 401
Beispiel #12
0
 def post(self):
     mail = request.args.get('mail')
     tag = request.args.get('tag')
     user = UserModel.find_by_mail(mail)
     if user:
         classe = ClassModel.find_by_tag(tag)
         if classe:
             user.classe_id = classe.id
             user.save_to_db()
             return {"message": "user added to class succesfully"}, 200
         return {"message": "class does not exist"}, 500
     return {"message": "user does not exist"}, 500
Beispiel #13
0
 def post(self):
     mail = request.args.get('mail')
     user = UserModel.find_by_mail(mail)
     if user:
         users = select_all()
         if users:
             for i in users:
                 i.ordine = None
                 user.save_to_db()
             return {"message": "users deleted"}, 200
         return {"message": "no users"}, 500
     return {"message": "user does not exist"}, 500
Beispiel #14
0
    def get(self, token):

        s = URLSafeTimedSerializer("password1")
        try:
            mail = s.loads(token, salt="emailconfirm")
            user = UserModel.find_by_mail(mail)
            if user:
                if user.confermato != True:
                    user.confermato = True
                    user.save_to_db()
                    return "user confirmed"
                return "user already confirmed", 400
            return "user does not exist", 400
        except:
            return "your token is expired"
Beispiel #15
0
 def post(self):
     mail=request.args.get('mail')
     oldPassword=request.args.get('oldPassword')
     newPassword=request.args.get('newPassword')
     user=UserModel.find_by_mail(mail)
     if user:
         epsw=oldPassword.encode('utf-8')
         hashed_password = hashlib.sha512(epsw).hexdigest()
         if user.password==hashed_password:
             epsw=newPassword.encode('utf-8')
             hashed_password = hashlib.sha512(epsw).hexdigest()
             user.password=hashed_password
             user.save_to_db()
             return {"message":"password changed successfully"}, 200
         return {"message":"wrong password"}, 401
     return {"message":"user does not exist"}, 500
Beispiel #16
0
    def post(self):
        data = request.get_json()
        mail = data[0]
        user = UserModel.find_by_mail(mail)
        if user:

            if user.classe_id:
                classe = find_by_id(user.classe_id)

                if user.admin == True:
                    classe.tag = randomtag()
                    classe.save_to_db()
                    return classe.tag
                return "user is not admin"
            return "user not in a class"
        return "user does not exist"
Beispiel #17
0
 def post(self):
     mail = request.args.get('mail')
     password = request.args.get('password')
     user = UserModel.find_by_mail(mail)
     epsw = password.encode('utf-8')
     if user and user.password == hashlib.sha512(
             epsw).hexdigest():  #and user.confirmed==True:
         expires = datetime.timedelta(days=365)
         access_token = create_access_token(identity=user.id,
                                            expires_delta=expires,
                                            fresh=True)
         refresh_token = create_refresh_token(user.id)
         return {
             "access_token": access_token,
             "refresh_token": refresh_token
         }, 200
     return {"message": "invalid cresdentials"}, 401
Beispiel #18
0
 def get(self):
     mail = request.args.get('mail')
     user = UserModel.find_by_mail(mail)
     if user:
         return {"message": user.username}
     return {"message": "user does not exist"}
Beispiel #19
0
def authenticate(username, password):
    user=UserModel.find_by_mail(username)
    epsw=password.encode('utf-8')
    hashed_password = hashlib.sha512(epsw).hexdigest()
    if user and user.password==hashed_password and user.confermato==True:
        return user