Ejemplo n.º 1
0
def register_page():
    if request.method == 'POST':
        username = request.form['user_name']
        password = request.form['password']
        firstname = request.form['first_name']
        lastname = request.form['last_name']
        email = request.form['email']
        status = search(username, password)
        if status == 'There is no user with this username ':
            current_app.user.username = username
            current_app.user.password = password
            current_app.user.name = firstname
            current_app.user.surname = lastname
            current_app.user.email = email
            session['user'] = username
            setUserToDb(current_app.user)
            markerLocations = []
            return render_template('user_page.html',
                                   markerLocations=markerLocations,
                                   user_name=username,
                                   first_name=firstname,
                                   last_name=lastname,
                                   e_mail=email)
        else:
            flash('The username: '******' already using by another user')
            return render_template('home.html')

    else:

        return render_template('home.html')
Ejemplo n.º 2
0
def sendRequests():
    if session.get('user')!=None:
        if request.method == 'POST':
            userName = request.form['user_name']
            status = search(userName,'someqw19012341')
            if userName != current_app.user.username:

                if status == 'Password is invalid':
                    currentName = current_app.user.username
                    relationStatus = current_app.friendStore.searchFriends(currentName,userName)
                    if relationStatus == 'alreadyExists':
                        flash('You are already friends 0_0 or you have been blocked :D')
                    else:
                        requestStatus = current_app.requestStore.searchRequests(currentName,userName)
                        if requestStatus == 'alreadySent':
                            flash('You already sent a friend request to '+userName)
                        elif requestStatus == 'alreadyReceived':
                            flash('You already received a friend request from '+userName+' Please check your Notifications page')
                        else:
                            requests = Request()
                            requests.requested = userName
                            requests.requester = current_app.user.username
                            current_app.requestStore.addRequest(requests)
                            flash('Friend request has been sent to '+userName)
                else:
                    flash('There is no user with this username: '******'very funny -_-')
        return render_template('friends.html',friends = current_app.friendStore.myFriends,userMap = current_app.usermap.myLocations, user_name = current_app.user.username,first_name=current_app.user.name,last_name = current_app.user.surname,e_mail=current_app.user.email)
    else:
        flash('Please sign in or register for DeepMap')
        return render_template('home.html')
Ejemplo n.º 3
0
def login_page():

    if request.method == 'POST':
        username = request.form['username1']
        password = request.form.get('password1', None)
        status = search(username, password)
        if status == 'Success':
            current_app.user = getUserFromDb(username)
            session['user'] = username
            current_app.usermap.getLocations(username)
            markerLocations = []
            for locations in current_app.usermap.myLocations:
                newLocation = {
                    'lat': locations.lat,
                    'lng': locations.lng,
                    'info': locations.mapInfo,
                    'label': locations.locationLabel
                }
                markerLocations.append(newLocation)

            current_app.commentStore.getComments(username)
            return render_template('user_page.html',
                                   comments=current_app.commentStore.comments,
                                   markerLocations=markerLocations,
                                   userMap=current_app.usermap.myLocations,
                                   user_name=username)
        else:
            flash(status)
            return render_template('home.html')

    if session.get('user') != None:
        markerLocations = []
        for locations in current_app.usermap.myLocations:
            newLocation = {
                'lat': locations.lat,
                'lng': locations.lng,
                'info': locations.mapInfo,
                'label': locations.locationLabel
            }
            markerLocations.append(newLocation)
        current_app.commentStore.getComments(username)
        return render_template('user_page.html',
                               comments=current_app.commentStore.comments,
                               markerLocations=markerLocations,
                               userMap=current_app.usermap.myLocations,
                               user_name=current_app.user.username,
                               first_name=current_app.user.name,
                               last_name=current_app.user.surname,
                               e_mail=current_app.user.email)

    else:
        flash('Please sign in or register for DeepMap')
        return render_template('home.html')
Ejemplo n.º 4
0
def sendMessages():
    if session.get('user') != None:
        if request.method == 'POST':
            userName = request.form['user_name']
            content = request.form['content']
            message = Message()
            message.sender = current_app.user.username
            message.receiver = userName
            message.content = content
            status = search(userName, 'someqw19012341')
            if userName != current_app.user.username:

                if status == 'Password is invalid':
                    currentName = current_app.user.username
                    relationStatus = current_app.friendStore.searchFriends(
                        currentName, userName)
                    if relationStatus == 'alreadyExists':
                        current_app.messageStore.sendMessage(message)
                        current_app.messageStore.getMessages(
                            current_app.user.username)
                        notification = Notification()
                        for conversation in current_app.messageStore.conversations:
                            if conversation.sender == userName:
                                for messages in conversation.messages:
                                    if message.sender == currentName and message.receiver == userName:
                                        notification.requester = currentName
                                        notification.requested = userName
                                        notification.typeId = messages.messageId
                        current_app.notificationStore.sendMessageNotification(
                            notification)
                    else:
                        flash('you are not friends with ' + userName)
                else:
                    flash('There is no user with this username: '******'very funny -_-')
        return render_template('messages.html',
                               messages=current_app.messageStore.conversations,
                               userMap=current_app.usermap.myLocations,
                               user_name=current_app.user.username,
                               first_name=current_app.user.name,
                               last_name=current_app.user.surname,
                               e_mail=current_app.user.email)
    else:
        flash('Please sign in or register for DeepMap')
        return render_template('home.html')
Ejemplo n.º 5
0
def test_search_one_channel():
    
    #create user
    workspace_reset()
    
    
    reg_cre = register_and_create()
    user = reg_cre['user']
    chan = reg_cre['channel']
    
    msg_test = send_msg1(user, chan)
    
    #test to see if search will return the messages that have helloworld
    query = "Testing"
    messages = search(token, query)

    #test to see if the query string used found messages in channels
    for i in messages['messages']:
        assert i['message'] == "Testing"
Ejemplo n.º 6
0
def test_search_short_query():
    
    #create user

    #make channel for user to be in and send message
    
    workspace_reset()
    register = reg_user1()
    
    token = register['token']
    u_id = register['u_id']
    
    payload = {
        'token' : register['token'],
        'name': 'firstChannel',
        'is_public': True
    }
    channel_id = channels_create(payload)
    
    payload1{
        'token':register['token'],
        'channel_id': channel_id,
        'message' : ""
    
    } 
    message_send(payload1)
       
    
    #test to see if search will return the messages that have ""
    query = ""
    
    payload2{
        'token':register['token'],
        'query': query    
    }
    
    messages = search(payload2)

    #test to see if the query string used found messages in channels
    for i in messages['messages']:
        assert i['message'] == ""
Ejemplo n.º 7
0
def test_search_no_message():
    
    #create user
    register = reg_user1()
    
    token = register['token']
    u_id = register['u_id']

    #make channel for user to be in and send message
    channel_id = channels_create(token, "validChannel", True)
    message_send(token, channel_id['channel_id'], "HelloWorld")

    #test to see if search will return the messages that have helloworld
    query = "NotAMessage"
    
    messages = search(token, query)
    
    counter = 0
    #test to see if the query string used found messages in channels
    for i in messages['messages']:
        assert i['message'] == "NotAMessage"
        counter=+1
        
    assert (counter == 0)
Ejemplo n.º 8
0
def test_search_multiple_channel():
    #create user
    workspace_reset()
    register = reg_user1()
    
    token = register['token']
    u_id = register['u_id']
    
    payload1{
        'token' : register['token'],
        'name': 'firstChannel',
        'is_public': True
    
    }
    
    channel_id = channels_create(payload1)
    payload2{
        'token':register['token'],
        'channel_id': channel_id,
        'message' : 'HelloWorld'
    
    }
    
    #make channel for user to be in and send message
    message_id = message_send(payload2)
    
    #make another channel for user to be in and send message
    payload3{
        'token' : register['token'],
        'name': 'firstChannel',
        'is_public': True
    
    }
    channel_id2 = channels_create(payload3)
    
    payload4{
        'token':register['token'],
        'channel_id': channel_id2,
        'message' : 'HelloWorld'
    
    }  
    
    message_id2 = message_send(payload4)
    
    #test to see if search will return the messages that have helloworld
    query = "HelloWorld"
    
    payload5{
        'token':register['token'],
        'query': query    
    }
    
    messages = search(payload5)
    
    counter = 0
    #test to see if the query string used found messages in channels
    for i in messages['messages']:
        assert i['message'] == "HelloWorld"
        counter=+1
        
    assert (counter == 2)