def post(self):
        flow = app.flow
        flow.redirect_uri = request.form["redirect_uri"]
        authCode = request.form["code"]
        flow.fetch_token(code=authCode)

        credentials = flow.credentials
        req_url = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + credentials.token
        user_info = requests.get(req_url).json()

        user = AuthenticationService.getUser(email=user_info['email'])

        if user:
            if not user.password:
                sessionId = uuid4()
                session = Session(user=user, sessionId=sessionId)
                session.save()
                ret = make_response(user_info)
                ret.set_cookie("SID",
                               str(session.sessionId),
                               expires=session.dateExpires)
                return ret
            return Response("Email already registered with our service",
                            status=403)
        else:
            ret = {}
            ret['message'] = "Redirect to complete sign up"
            ret['user'] = user_info
            return Response(ret, status=200)
Beispiel #2
0
def MenuService(CurrentUser: User):

    while True:
        print("\nChange operation :")
        print("Withdraw money - 1")
        print("See balance - 2")
        print("Exit - 3")
        event = int(input())
        if event == 1:
            try:
                print("Available bill")
                for item in BankomatRepositorieFunctions.GetAvailableBill()[0]:
                    print(item, end=' ')
                print()
                print("Enter password")
                EnterPassword = int(input())
                CurrentSession = Session(CurrentUser, EnterPassword)
                UserServiceFunctions.Login(
                    CurrentSession, FinancialServiceFunctions.WithdrawMoney)
                print("Take your Money")

            except Excp.BlockAccount as e:
                raise e
            except Excp.NotEnoughtMoney as e:
                print(e)
            except Excp.NotHaveBill as e:
                print(e)

            except Excp.BigSum as e:
                print(e)
            except ValueError:
                print("Wrong argument")
            break

        elif event == 2:
            try:
                print("Enter password")
                EnterPassword = int(input())
                CurrentSession = Session(CurrentUser, EnterPassword)
                UserServiceFunctions.Login(
                    CurrentSession, UserServiceFunctions.ShowUserBalance)
            except Excp.BlockAccount as e:
                raise e
            except ValueError:
                raise ValueError
            break

        elif event == 3:
            print("Good luck")
            break

        else:
            print("incorreect operation")
            break
Beispiel #3
0
    def authenticate(self, email, password):
        hashedPassword = self.saltPassword(password)
        user = self.getUser(email=email)

        if not user:
            return False

        if hashedPassword != user.password:
            return False

        sessionId = uuid4()
        session = Session(user=user, sessionId=sessionId)
        session.save()
        return session
 def get_current_user(self):
     if self.user is None:
         session = Session.get_from_cookie(self)
         if session is not None:
             session.save()
             self.user = User.find(session.user_model_id)
     return self.user
Beispiel #5
0
def getMerchants():
    merchants = Session.getMerchants(aClient)
    ms =[]
    s = None
    for m in merchants:
        s = json.dumps(m.__dict__)
        ms.append(s)
    return json.dumps(ms)
    def post(self):
        user = {
            "firstName": request.form["firstName"],
            "lastName": request.form["lastName"],
            "email": request.form["email"],
            "password": request.form["password"],
            "organization": request.form["organization"],
            "location": request.form["location"],
            "userType": request.form["userType"]
        }

        try:
            User.objects.get(email=user["email"])
            return Response(
                "There's already an account with the provided email.",
                status=400)
        except:
            try:
                AuthenticationService.signup(user)
                userConfirmationId = uuid4()
                user = User.objects.get(email=user["email"])
                if AuthenticationService.isUserConfirmed(user):
                    sessionId = uuid4()
                    session = Session(user=user, sessionId=sessionId)
                    session.save()
                    data = {
                        "message": "Google authorized successful!",
                        "user": user.email
                    }
                    ret = make_response(data)
                    ret.set_cookie("SID",
                                   str(session.sessionId),
                                   expires=session.dateExpires)
                    return ret
                AuthenticationService.setUserConfirmationId(
                    user, userConfirmationId)
                sub = "Confirm Account"
                msg = f"<p>Congratulations, you've registered for Agriworks. Please click the link below to confirm your account.</p><p><a href=\"{app.rootUrl}/confirm-user/{userConfirmationId}\"> Confirm account </a></p>"
                MailService.sendMessage(user, sub, msg)
                return Response("Signup successful", status=200)
            except:
                return Response("Signup unsuccessful. Please try again.",
                                status=403)
Beispiel #7
0
def getMerchants():
    b = False
    if currentItemCount > 0:
        b = True
    merchants = Session.getMerchants(aClient, b)
    ms =[]
    s = None
    print(merchants[merchants.keys()[0]])
    for m in merchants:
        print(m.__class__)
        s = json.dumps(m)
        ms.append(s)
    return json.dumps(ms)
Beispiel #8
0
def main():
    #FinancialServiceFunctions.BillAdding({ 1: 10, 2 : 10, 5 : 10, 10 : 10, 20 : 20, 50 : 10, 100 : 10, 200 : 10, 500 : 100})
    #UserServiceFunctions.AddAccount(User("Urii","Kovalenko",8445,1245,7,0))
    CurrentSession = None
    while True:
        try:
            if CurrentSession != None:  #If Session is created
                raise Excp.SessionIsOver
            print("Enter user account number")
            EnterUserAccount = int(input())
            CurrentUser = UserRepositorieFunctions.GetUserInfo(
                EnterUserAccount)

        except Excp.AccountIsBlocked as e:
            print(e)
            continue
        except Excp.NotFoundAccount as e:
            print(e)
            continue
        except Excp.SessionIsOver:
            pass
        except ValueError:
            print("Data was entered wrong ")
            continue

        while True:
            try:
                print("Enter the password")
                EnterPassword = int(input())
                CurrentSession = Session(CurrentUser, EnterPassword)
                UserServiceFunctions.Login(CurrentSession, MenuService)
                CurrentSession = None
                break

            except Excp.BlockAccount as e:
                UserRepositorieFunctions.BlockAccount(
                    CurrentUser.NumberOfAccount)
                BankomatRepositorieFunctions.MakeNoteToActions(
                    "Account {} is blocked for 1 minute ".format(
                        CurrentUser.NumberOfAccount))
                CurrentSession = None
                print(e)
                break
            except Excp.WrongPassword as e:
                print(e)
                continue
            except ValueError:
                print("Wrong Argument")
                CurrentSession = None
                break
    return
def insertSession():
    session_collection = mongo.db.sessions
    new_session = Session(request.form.get("user_id", False),
                          request.form.get("first_received_at", False),
                          request.form.get("topic", False),
                          request.form.get("focus_score", False),
                          request.form.get("transcribed_at", False),
                          request.form.get("transcribed_speech",
                                           False)).__dict__

    session_collection.insert_one(new_session)
    new_session['_id'] = str(new_session['_id'])

    return jsonify({'new_session': new_session})
 def do_login(self):
     user_name = self.get_argument("user")
     password = self.get_argument("password")
     user = User.authenticate_user(user_name,
                                   password)  # either false or user object
     if user:  # login worked
         session = Session(user_model_id=user.model_id)
         session.save()
         session.set_cookie(self)
     self.redirect('/')
Beispiel #11
0
def login():
    user = Session.login(aClient)
    s = json.dumps(user.__dict__)
    return s
 def do_logout(self):
     if self.current_user is not None:
         session = Session.get_from_cookie(self)
         session.clear_cookie(self)
         session.delete()