Пример #1
0
def login():
    returnData = {
        "success": False,
        "data": {
            "username": None
        },
        "notifications": None
    }

    email = request.form.get('username', None)
    passwordFromClient = request.form.get('password', None)

    returnData["data"]["username"] = email

    if email is None or passwordFromClient is None:
        notifications.append(notifications.notification(1))
        return formatJsonWithNotifications(returnData)

    # get password
    result = mf_database.getUserIdPassword(email)

    if result == -1:
        notifications.append(notifications.notification(1))
        return formatJsonWithNotifications(returnData)

    (userId, hashedPasswordFromDatabase) = result

    if check_password_hash(hashedPasswordFromDatabase, passwordFromClient):
        session["id"] = userId
        session["username"] = email
        returnData["success"] = True
        return formatJsonWithNotifications(returnData)
    else:
        notifications.append(notifications.notification(1))
        return formatJsonWithNotifications(returnData)
Пример #2
0
def newuser(request):
    email = request.get('form_new_email', 0)
    nickname = request.get('form_new_nick', 0)
    password = request.get('form_new_pass', 0)
    repeat_password = request.get('form_new_pass_repeat', 0)

    user = {}
    user["data"] = {"email": email, "nickname": nickname}
    if password == repeat_password:
        result = back_user.register_user(email, password, nickname)
        user["success"] = result
        if not result:
            n.append(n.notification(3))
    else:
        n.append(n.notification(2))
        user["success"] = False
    user["notifications"] = n.flush()
    return user
Пример #3
0
def calendar_edit_form():
    calendarId = request.form.get('form_calendar_id', None)
    newCalendarName = request.form.get('form_calendar_name', None)
    newPublicStatus = request.form.get('form_calendar_public', None)

    returnData = {
        "success": False,
        "data": {
            "id": calendarId,
            "name": newCalendarName,
            "public": None
        },
        "notifications": None
    }

    if calendarId is None or newCalendarName is None:
        notifications.append(notifications.notification(6))
        return formatJsonWithNotifications(returnData)

    if not isLoggedIn():
        notifications.append(notifications.notification(6))
        return formatJsonWithNotifications(returnData)
    userId = session["id"]

    newIsPublic = True if newPublicStatus == "public" else False

    returnData["data"]["public"] = newIsPublic

    wasSuccessful = mf_database.editCalendar(newCalendarName, newIsPublic,
                                             calendarId, userId)

    if wasSuccessful == -1:  # -1 is not successful
        notifications.append(notifications.notification(6))
        return formatJsonWithNotifications(returnData)

    returnData["success"] = True
    return formatJsonWithNotifications(returnData)
Пример #4
0
def event_calendar_list(params):
    calendar_id = params["args"].get("calendar_id", 0)
    calendar_events = db.get_all_calendar_events_db(session['id'], calendar_id)
    returner = []
    for event_id, _ in calendar_events:
        event = db.get_event_db(session['id'], event_id)
        event = {
            "id": event_id,
            "calendar_id": calendar_id,
            "name": event[1],
            "start": str(event[3]),
            "end": str(event[4])
        }
        returner.append(event)
    if len(returner) == 0:
        n.append(n.notification(7))
    return returner
Пример #5
0
def calendar_edit_form(request):
    id = request.get('form_calendar_id', 0)
    name = request.get('form_calendar_name', 0)
    if request('form_calendar_public', 0) == 'public':
        public = True
    else:
        public = False
    calendar = {
        "success": db.edit_calendar_db(session['id'], id, name, public),
        "data": {
            "id": id,
            "name": name,
            "public": public
        }
    }
    if not calendar["success"]:
        n.append(n.notification(6))
    calendar["notifications"] = n.flush()
    return calendar
Пример #6
0
def login(request):
    username = request.get('username', 0)
    password = request.get('password', 0)
    login_db = back_user.login(username, password)
    if login_db['success']:
        session['id'] = login_db['user_id']
        session['username'] = username
        session['login'] = True
        resultat = {
            "success": login_db['success'],
            "data": {
                "username": username
            }
        }
    else:
        n.append(n.notification(1))
        resultat = {
            "notifications": n.flush(),
            "success": login_db['success'],
            "data": {
                "username": username
            }
        }
    return resultat
Пример #7
0
from config import config
from user_notif import user_notif
from notifications import notification

configuration = config() #object for reading saved configuration
musicfolder = configuration.get('music folder').replace('\n','') 
notifications = configuration.get('notifications').replace('\n','')
watchedfolders = configuration.get('watched folders').split(':')

unotif = user_notif() #object for controlling notification of moved music file

#
#setting up notification system
#
if (notifications=='True'):
	notif = notification()
else:
	notif = None
#
# Class for handling events from inotify
#
class EventHandler(pyinotify.ProcessEvent):
	def __init__(self):
		self.tmp = 0
	def process_IN_CLOSE_WRITE(self,event):
		place(event.pathname)
	def process_IN_MOVED_TO(self,event):
		place(event.pathname)
def ismusicfile(filepath):
	if filepath.endswith('.mp3'):
		return True
Пример #8
0
    joinChat(browser, configParams[0], configParams[1], configParams[2])
    oldListElements = getFiveLastElements(browser)
    time.sleep(5)
    while True:
        listElements = getFiveLastElements(browser)
        uniqueSet = compareListsElement(listElements, oldListElements)
        uniqueList = list(uniqueSet)
        #print("unique: ", uniqueList)
        for unique in uniqueList:
            time.sleep(1)
            #print("MSG: ", unique)
            listNickMsg = unique.split(": ", 1)
            print("SPLIT: ", listNickMsg)
            '''notifications'''
            if len(listNickMsg) == 1:
                if (notification(browser, listNickMsg, unique)) == False:
                    print("### notification false ###")
            '''notifications'''
            '''users input '''
            if len(listNickMsg) == 2:
                if (general(browser, listNickMsg, unique)) == False:
                    print("### general false ###")
                if (accosted(browser, listNickMsg, unique)) == False:
                    print("### accosted false ###")
                if (special(browser, listNickMsg, unique)) == False:
                    print("### special false ###")
                if (command(browser, listNickMsg, unique)) == False:
                    print("### command false ###")
            '''users input'''
            #TODO: jak sie czujesz
Пример #9
0
def createNewUser():
    returnData = {
        "data": {
            "email": None,
            "nickname": None
        },
        "success": False,
        "notifications": None
    }

    email = request.form.get('form_new_email', "")
    nickname = request.form.get('form_new_nick', "")
    password = request.form.get('form_new_pass', "")
    repeat_password = request.form.get('form_new_pass_repeat', "")

    returnData["data"]["email"] = email
    returnData["data"]["nickname"] = nickname

    if email == "" or nickname == "" or password == "" or repeat_password == "":
        notifications.append(notifications.notification(3))
        return formatJsonWithNotifications(returnData)
    if password != repeat_password:
        notifications.append(notifications.notification(2))
        return formatJsonWithNotifications(returnData)

    # valid username and password
    # # proper username?
    match = re.match(
        '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$',
        email)
    if match is None:
        notifications.append(notifications.notification(
            3))  # TODO: replace with better notifications
        return formatJsonWithNotifications(returnData)
    # # usename already in use?
    uniqueUsername = mf_database.checkEmailInUse(email)

    if uniqueUsername == -1:  # error happened
        notifications.append(notifications.notification(3))
        return formatJsonWithNotifications(returnData)

    if not uniqueUsername:
        notifications.append(notifications.notification(3))
        return formatJsonWithNotifications(returnData)

    # # proper password?
    #TODO: some password validity test

    # hash password and create salt
    salt = os.urandom(10).hex()
    hashedPassword = generate_password_hash(password,
                                            method='pbkdf2:sha256',
                                            salt_length=8)

    # create user
    userId = mf_database.createUser(email, hashedPassword, salt, nickname)

    if userId == -1:
        notifications.append(notifications.notification(3))
        return formatJsonWithNotifications(returnData)

    # create standard calendar
    calendarName = nickname + "\'s calendar"
    # # add in calendar
    result = mf_database.createNewCalendar(userId, calendarName, False)

    if result == -1:
        notifications.append(notifications.notification(3))
        return formatJsonWithNotifications(returnData)

    #
    returnData["success"] = True
    return formatJsonWithNotifications(returnData)