def unlikepost(): model_object = UserModel() like = likes_post() like.liked_by_id = session['user']['user_id'] like.post_id = request.args["post_id"] likes = model_object.unlikepost(like) return likes
def unfriend(): objfriends = friends() objfriends.user_id = request.args["profile_id"] objfriends.friend_id = session["user"]["user_id"] model_object = UserModel() profile_id = model_object.unfriend(objfriends) return str(profile_id)
def postcontent(): objuser = user_post() user = session["user"] objuser.user_id = user["user_id"] objuser.content = request.form["txtcontent"] objuser.title = request.form["txttitle"] location = request.form["txtlocation"] if request.form["selectvisibility"]: objuser.visibility_id = request.form["selectvisibility"] if 'fileupload' in request.files: print "in" try: objuser.upload = upload_content(request.files['fileupload']) except Exception as ex: print str(ex) model_object = UserModel() post_id = model_object.postcontent(objuser, location) posts = [] post = { "post_id": post_id, "first_name": user["first_name"], "last_name": user["last_name"], "title": objuser.title, "posted_when": objuser.posted_when, "content": objuser.content, "upload": str(objuser.upload), "user_id": user["user_id"], "location": location, "likes": {} } posts.append(post) return render_template("posts.html", posts=posts, user=session["user"])
def postcontent(): objuser = user_post() user = session["user"] user_post.user_id = user["user_id"] user_post.content = request.form["txtcontent"] user_post.title = request.form["txttitle"] if request.form["selectvisibility"]: user_post.visibility_id = request.form["selectvisibility"] if request.files['fileupload']: try: fileupload = request.files['fileupload'] if fileupload and allowed_file(fileupload.filename): # Make the filename safe, remove unsupported chars filename = secure_filename(fileupload.filename) ext=filename.split('.') filename=secure_filename(user['first_name'] + "_" + str(datetime.now()) + "." + ext[len(ext)-1]) fileupload.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) user_post.upload = filename except Exception as ex: print str(ex) model_object = UserModel() model_object.postcontent(objuser) posts = [] post = { "first_name" : user["first_name"], "last_name" : user["last_name"], "title" : user_post.title, "posted_when" : user_post.posted_when, "content" : user_post.content, "upload" : str(user_post.upload) } print post posts.append(post) return render_template("posts.html", posts = posts)
def unlikecomment(): model_object = UserModel() like = likes_comment() like.liked_by_id = session['user']['user_id'] like.comment_id = request.args["comment_id"] likes = model_object.unlikecomment(like) return likes
def add_user(): request = { "username":"******", 'password':"******" } UserModel.add_user(request["username"], request["password"]) return 'doctors'
def post(self): data = _user_parser.parse_args() if UserModel.find_by_username(data['username']): return {"message": "User already exists!"}, 400 user = UserModel(**data) user.save_to_db() return {"message": "User created successfully."}, 201
def addfriend(): objfriend_requests = friend_requests() objfriend_requests.to_id = request.args["profile_id"] objfriend_requests.from_id = session["user"]["user_id"] model_object = UserModel() request_id = model_object.addfriend(objfriend_requests) return str(request_id)
def decline(): objfriend_requests = friend_requests() objfriend_requests.request_id = request.args["request_id"] objfriend_requests.from_id = request.args["profile_id"] objfriend_requests.to_id = session["user"]["user_id"] model_object = UserModel() model_object.declinefriend(objfriend_requests) return ""
def post(self): data = UserRegister.parser.parse_args() if UserModel.find_by_username(data["username"]): return {"message": "User with that userid already exist"}, 400 user = UserModel(**data) # **data = data["username"], data["password"] user.save_to_db() return {"message": "User created successfully"}, 201
def post(self): '''edit a user by id''' data = api.payload user = UserModel(full_name=data['full_name'], password=generate_password_hash(data['password']), email=data['email']) user.save_to_db() return user_schema.dump(user)
def saveadditional(): user_profile = usr_profile() user_profile.school = request.args["txtschool"] user_profile.university = request.args["txtuniversity"] user_profile.job = request.args["txtjob"] model_object = UserModel() model_object.saveadditional(session["user"]["user_id"], user_profile) return redirect('/wall')
def login(): fields = users() model_object = UserModel() fields.email_id = request.form["txtusername"] fields.password = request.form["txtuserpassword"] if model_object.login(fields): return "1" return "0"
def update_score(self, score): self.score = score self.isFinished = True # also update the player score UserModel.find_by_id(self.userId).add_score(score) db.session.commit()
def register(): fields = users() model_object = UserModel() fields.first_name = request.form["txtfname"] fields.last_name = request.form["txtlname"] fields.email_id = request.form["txtemail"] fields.password = request.form["txtpassword"] model_object.register_user(fields) return "text"
def post(self): connection = sqlite3.connect("data.db") cursor = connection.cursor() data = UserResgiter.parser.parse_args() if UserModel.find_by_username(data['username']): return {'msg': "user already registered"} user = UserModel(**data) user.save_to_db() return {'msg': "user registered successfully"}
def post(self): data = UserRegister.parser.parse_args() if UserModel.find_by_username(data["username"]): return {"message": "User already exists"}, 400 user = UserModel(data['username'], data['password']) user.save_to_db() return {"message": "User created successfully"}, 201
def post(self): request_date = UserRegister.parser.parse_args() if UserModel.find_user_by_username(request_date['username']): return { 'Message': f"The username {request_date['username']} is already exist" }, 400 user = UserModel(**request_date) user.save_to_db() return {'Message': 'User Register Successfully...'}, 201
def post(self): data = UserRegister.parser.parse_args() if UserModel.find_by_username(data['username']): return {"message": "A user with this username already exists"}, 400 user = UserModel(**data) user.save_to_db() return {"message": "User created successfully"}, 201
def wall(): model_object = UserModel() posts = model_object.get_posts(session["user"]["user_id"]) msgs = model_object.get_messages(session["user"]["user_id"]) requests = model_object.get_friend_requests(session["user"]["user_id"]) return render_template('index.html', posts=posts, user=session["user"], requests=requests, msgs=msgs)
def post(self): data = UserRegister.parser.parse_args() if UserModel.find_by_username(data["nom_authent"]): return {"message": "User déjà existant"}, 400 user = UserModel(** data) #**data= data["nom_authent"], data["password"] user.save_to_db() return {"message": "Utilisateur créé"}, 201
def post(self): data = UserRegister.parser.parse_args() if UserModel.find_by_username(data['username']) is not None: # check if username already exists return {"message": "User with that name already exists"}, 400 user = UserModel(data['username'], data['password']) user.save_to_db() return {"message": "Account created"}, 201 # 201 is created
def post(): data = _user_parser.parse_args() # select_query = "SELECT username FROM users" if UserModel.find_by_username(data['username']): return {"message": "user already exists"}, 400 user = UserModel(**data) user.save_to_db() return {"message": "User was created"}, 201
def post(self): data = UserRegister.parser.parse_args() if UserModel.find_by_username(data['username']): return { 'message': "User '{}' already exists!".format(data['username']) }, 400 user = UserModel(**data) user.save_to_db() return {'message': 'User created successfully.'}, 201
def post(self): ''' use this to authenticate users''' data = api.payload email = data['email'] if UserModel.check_if_mail_exists(email): if UserModel.check_passoword(data['password'], email): user_id = UserModel.get_user_id(email) access_token = create_access_token(identity=user_id) return {'access_Token': access_token} else: return {'message': 'Invalid login credentials'}, 401 else: return {'message': 'Invalid login credentials'}, 401
def authenticate(username, password): user = UserModel.find_by_username(username) # print(username) # print(password) # print(user) if user and safe_str_cmp(user.password, password): # safer for different encoding cases, than string == string return user
def delete(cls, user_id): user = UserModel.find_by_id(user_id) if not user: return {'message': 'User Not found'}, 404 else: user.delete_from_db() return {'message': 'User deleted'}, 200
def delete(self, _id): '''delete a user by id''' user = UserModel.fetch_by_id(_id) if user: user.delete_from_db() return {'message': 'user deleted successfully'} else: return {'message': 'That user does not exist'}
def login(): userInfo = request.get_json() # get inputted data from login form username = userInfo['username'] password = userInfo['password'] # create a usermodel object um = UserModel() # confirm credentials to those on server userInfo = um.confirm_credentials(username, password) if not userInfo: isvalid = False else: isvalid = True # if isvalid is true, return json of information, otherwise return invalid credentials if isvalid: return jsonify(userInfo) else: return 'invalid credentials'
def post(self): data = UserSignOn.parser.parse_args() emailId = data['email'] userName = data['username'] passWord = data['password'] # check if the user already exists if UserModel.getUserByEmail(emailId): returnMessage = "User with email: {email} already exists, please select a new email.".format( email=emailId) return {"message": returnMessage}, 400 # otherwise sign on the new user user = UserModel(emailId, userName, passWord) user.Save() returnMessage = "Congrats {usernm} !!!, Your have been successful registerted with email: {email}.".format( usernm=userName, email=emailId) return {"message": returnMessage}, 201
def comment(): comment = comments() comment.content = request.args["comment"] comment.post_id = request.args["post_id"] comment.user_id = session["user"]["user_id"] model_object = UserModel() rowid = model_object.comment(comment) resp = '<div class="row" id="%s" style="background-color:#f5f5f5;">\ <div class="col-md-6" style="padding-left:30px;">\ <a href="#" class="text-info">%s</a> \ %s <small><em class="text-warning">%s</em></small>\ <br>\ <small><a href="#" data-toggle="tooltip" data-html="true" href="#" data-original-title="" class="acommentlike" type="like">Like</a></small>\ </div>\ <br>\ <hr>\ </div>' % (rowid, session["user"]["first_name"], comment.content, comment.commented_when) return resp
def wall(): model_object = UserModel() posts = model_object.get_posts(session["user"]["user_id"]) return render_template('index.html', fname=session['user']['first_name'], posts=posts)