def user_profiles_uploadphoto(token, img_url, x_start, y_start, x_end, y_end): global image_name image_name += 1 filePath = './static/' + str(image_name) + '.jpg' downloadImage(img_url, filePath) #crop image img_obj = Image.open(filePath) width, height = img_obj.size #no input if x_start is None and x_end is None and y_start is None and y_end is None: x_start = 0 x_end = width y_start = 0 y_end = height x_start = int(x_start) y_start = int(y_start) x_end = int(x_end) y_end = int(y_end) #x_start and y_start has to be less than width and hight if x_end > width or y_end > height or x_start >= x_end or y_start >= y_end: raise ValueError_http( f"Crop has to be within the dimension ({width} x {height})") cropped = img_obj.crop((x_start, y_start, x_end, y_end)) #save cropped image filePath_cropped = './static/' + str(image_name) + '_cropped' + '.jpg' #print(final_url) cropped.save(filePath_cropped) final_url = 'http://localhost:' + sys.argv[1] + '/static/' + str( image_name) + '_cropped.jpg' getUserFromToken(token)['profile_img_url'] = final_url
def user_profile_sethandle(token, handle_str): if len(handle_str) < 3 or len(handle_str) > 20: raise ValueError_http("handle_str should be between 3-20 characters") if getUserByHandle(handle_str) != None: raise ValueError_http( "handle_str is already being used by another user") found_user2 = getUserFromToken(token) found_user2['handle_str'] = handle_str return ({})
def user_profile_setname(token, name_first, name_last): validUserT = getUserFromToken(token) if len(name_first) > 50: raise ValueError_http( "Invalid name_first, above the range of 50 characters") if len(name_last) > 50: raise ValueError_http( "Invalid name_last, above the range of 50 characters") if validUserT != None: validUserT['name_first'] = name_first validUserT['name_last'] = name_last return ({})
def user_profile(token, u_id): valid_userT = getUserFromToken(token) valid_userU = getUserById(u_id) return ({ 'u_id': valid_userU['u_id'], 'email': valid_userU['email'], 'name_first': valid_userU['name_first'], 'name_last': valid_userU['name_last'], 'handle_str': valid_userU['handle_str'], 'profile_img_url': valid_userU['profile_img_url'], })
def standup_send(token, channel_id, message): channel = getChannelFromChannelId(channel_id) if channel['standup_active'] is False: raise ValueError_http('Standup not currently active') #send message normally message_send(token, channel_id, message) #add message to a list msg_with_names = getUserFromToken( token)['handle_str'] + ": " + message + "\n" getChannelFromChannelId(channel_id)['standup_msg'] += msg_with_names
def user_profile_setemail(token, email): data = getData() #'''Email entered is not a valid email''' if not re.match(r"[^@]+@[^@]+\.[^@]+", email): raise ValueError_http("Invalid email") # if getUserByEmail(email) != None: for user in data['users']: if user['email'] == email: raise ValueError_http( "Email address is already being used by another user") found_user = getUserFromToken(token) found_user['email'] = email return ({})
def users_all(token): data = getData() foundUser = getUserFromToken(token) all_users = [] for user in data['users']: user_dic = { 'u_id': user['u_id'], 'email': user['email'], 'name_first': user['name_first'], 'name_last': user['name_last'], 'handle_str': user['handle_str'], 'profile_img_url': user['profile_img_url'] } all_users.append(user_dic) return { 'users': all_users, }
def admin_userpermission_change(token, u_id, permission_id): # check if permission_id is a valid value for permission_id if permission_id != 1 and permission_id != 2 and permission_id != 3: raise ValueError_http( "Permission_id doesn't refer to a value permission.") foundUser1 = getUserFromToken(token) # check if token is valid foundUser2 = getUserById(u_id) # check if u_id is valid # check if token refer to a member, not an admin or owner if foundUser1['permission_id'] == 3: raise AccessError("Authorised user is not an admin or owner") # check if token refers to admin elif foundUser1['permission_id'] == 2: # u_id refers to member if foundUser2['permission_id'] == 3: # permission_id is 3 (member) if permission_id == 3: raise ValueError_http("User is already a member.") # permission_id is 2 (admin) elif permission_id == 2: foundUser2['permission_id'] = 2 # permission_id is 2 (owner) elif permission_id == 1: raise ValueError_http("Authorised user is not an owner.") # u_id refers to an admin elif foundUser2['permission_id'] == 2: # permission_id is 3 (member) if permission_id == 3: foundUser2['permission_id'] = 3 # permission_id is 2 (admin) elif permission_id == 2: raise ValueError_http("User is already an admin.") elif permission_id == 1: raise ValueError_http("Authorised user is not an owner.") # u_id refers to an owner elif foundUser2['permission_id'] == 1: # permission_id is 3 (member) if permission_id == 3: raise ValueError_http("Authorised user is not an owner.") # permission_id is 2 (admin) elif permission_id == 2: raise ValueError_http("Authorised user is not an owner.") elif permission_id == 1: raise ValueError_http("Authorised user is not an owner.") # check if token refers to an owner elif foundUser1['permission_id'] == 1: # u_id refers to a member if foundUser2['permission_id'] == 3: # permission_id is 3 (member) if permission_id == 3: raise ValueError_http("User is already a member.") # permission_id is 2 (admin) elif permission_id == 2: foundUser2['permission_id'] = 2 # permission_id is 2 (owner) elif permission_id == 1: foundUser2['permission_id'] = 1 # u_id refers to an admin elif foundUser2['permission_id'] == 2: # permission_id is 3 (member) if permission_id == 3: foundUser2['permission_id'] = 3 # permission_id is 2 (admin) elif permission_id == 2: raise ValueError_http("User is already an admin.") elif permission_id == 1: foundUser2['permission_id'] = 1 # u_id refers to an owner elif foundUser2['permission_id'] == 1: if foundUser1 == foundUser2: foundOwner = check_last_owner(u_id) if foundOwner == 1: raise ValueError_http("You're the last owner!") elif foundOwner > 1: foundUser2['permission_id'] = 1 # permission_id is 3 (member) if permission_id == 3: foundUser2['permission_id'] = 3 # permission_id is 2 (admin) elif permission_id == 2: foundUser2['permission_id'] = 2 elif permission_id == 1: raise ValueError_http("User is already an owner.") return ({})