def badge_achievement(): badgecount = Userbadges.query.filter_by(user_id=current_user.id).count() if badgecount >=5: badgeachievementfirst = Userachievements.query.filter(Userachievements.achievement_id == 14, Userachievements.user_id == current_user.id).all() if not badgeachievementfirst: badgeachievement = Userachievements(achievement_id=14, user_id=current_user.id) badgepoint = Userpoints(reason='Get 5 badges', points_id=20, user_id=current_user.id) db.session.add(badgeachievement) db.session.add(badgepoint) db.session.commit() if badgecount >=10: badgeachievementsecond = Userachievements.query.filter(Userachievements.achievement_id == 15, Userachievements.user_id == current_user.id).all() if not badgeachievementsecond: badgeachievement = Userachievements(achievement_id=15, user_id=current_user.id) badgepoint = Userpoints(reason='Get 10 badges', points_id=21, user_id=current_user.id) db.session.add(badgeachievement) db.session.add(badgepoint) db.session.commit() if badgecount >=20: badgeachievementsecond = Userachievements.query.filter(Userachievements.achievement_id == 16, Userachievements.user_id == current_user.id).all() if not badgeachievementsecond: badgeachievement = Userachievements(achievement_id=16, user_id=current_user.id) badgepoint = Userpoints(reason='Get 20 badges', points_id=22, user_id=current_user.id) db.session.add(badgeachievement) db.session.add(badgepoint) db.session.commit() return badgecount
def posterpoint_achievement(pid): post = Post.query.filter_by(post_id=pid).first() points = db.session.query(Userpoints.user_id, func.sum(Pointrules.add_points)).outerjoin(Pointrules, Userpoints.points_id == Pointrules.point_id).group_by(Userpoints.user_id).filter(Userpoints.user_id==post.user_id).all() #print(points) if points: if points[0][1] >= 220: #print(points[0][1]) pointachievementfirst = Userachievements.query.filter(Userachievements.achievement_id == 11, Userachievements.user_id == points[0][0]).all() #print(pointachievementfirst) if not pointachievementfirst: pointachievement = Userachievements(achievement_id=11, user_id=points[0][0]) pointpoint = Userpoints(reason='The points reach to 220', points_id=17, user_id=points[0][0]) db.session.add(pointachievement) db.session.add(pointpoint) db.session.commit() if points[0][1] >= 540: #print(points[0][1]) pointachievementsecond = Userachievements.query.filter(Userachievements.achievement_id == 12, Userachievements.user_id == points[0][0]).all() if not pointachievementsecond: pointachievement = Userachievements(achievement_id=12, user_id=points[0][0]) pointpoint = Userpoints(reason='The points reach to 540', points_id=18, user_id=points[0][0]) db.session.add(pointachievement) db.session.add(pointpoint) db.session.commit() return post, points
def deleteuserreport_point(pid): report = Userreport.query.filter_by(report_id=pid).first() deleteuserreport = Userpoints(reason='IT delete your report' + ' "' + report.subject + '"', points_id=6, user_id=report.user_id) db.session.add(deleteuserreport) return pid, deleteuserreport
def register_point(): form = RegistrationForm() currentuser = User.query.filter_by(email=form.email.data).first() pointrecord = Userpoints(reason="Register", points_id=7, user_id=currentuser.id) db.session.add(pointrecord) db.session.commit() return form, currentuser, pointrecord
def report_point(): form = UserReportForm() reportpoint = Userpoints(reason='Report an attack' + ' "' + form.subject.data + '"', points_id=4, user_id=current_user.id) db.session.add(reportpoint) db.session.commit() return form, reportpoint
def post_point(): form = PostForm() postpoint = Userpoints(reason='Share an experience' + ' "' + form.title.data + '"', points_id=1, user_id=current_user.id) db.session.add(postpoint) db.session.commit() return form, postpoint
def responsepost_achievement(): likerecord = Userpoints.query.filter(Userpoints.user_id == current_user.id, Userpoints.points_id == 2).count() dislikerecord = Userpoints.query.filter(Userpoints.user_id == current_user.id, Userpoints.points_id == 3).count() recordcount = likerecord + dislikerecord postlikeachievementfirst = Userachievements.query.filter(Userachievements.achievement_id == 3, Userachievements.user_id == current_user.id).all() postlikeachievementsecond = Userachievements.query.filter(Userachievements.achievement_id == 4, Userachievements.user_id == current_user.id).all() if recordcount >= 20: if not postlikeachievementfirst: postlikeachievement = Userachievements(achievement_id=3, user_id=current_user.id) postlikeachievementpoint = Userpoints(reason='The amount of clicking "Like" or "Not Interested" reach to 20', points_id=9, user_id=current_user.id) db.session.add(postlikeachievement) db.session.add(postlikeachievementpoint) db.session.commit() if recordcount >= 150: if not postlikeachievementsecond: postlikeachievement = Userachievements(achievement_id=4, user_id=current_user.id) postlikeachievementpoint = Userpoints(reason='The amount of clicking "Like" or "Not Interested" reach to 150', points_id=10, user_id=current_user.id) db.session.add(postlikeachievement) db.session.add(postlikeachievementpoint) return likerecord, dislikerecord, recordcount, postlikeachievementfirst, postlikeachievementsecond
def post_achievement(): postachievement = Userachievements.query.filter(Userachievements.achievement_id == 2,Userachievements.user_id == current_user.id).all() postrecord = Userpoints.query.filter(Userpoints.points_id == 1, Userpoints.user_id == current_user.id).count() if postrecord == 10: if not postachievement: postachievementrecord = Userachievements(achievement_id=2, user_id=current_user.id) postachievementpoint = Userpoints(reason='The amout of the posting experience reach to 10', points_id=8, user_id=current_user.id) db.session.add(postachievementrecord) db.session.add(postachievementpoint) db.session.commit() return postachievement, postrecord
def belikedpost_achievement(pid): post = Post.query.filter_by(post_id=pid).first() belikedposts = db.session.query(Post.user_id, func.count(LikePostRecord.id)).outerjoin(LikePostRecord, Post.post_id == LikePostRecord.post_id).group_by(Post.user_id).filter(Post.user_id == post.user_id).all() #print(belikedposts) if belikedposts[0][1] >= 20: belikedachievementfirst = Userachievements.query.filter(Userachievements.achievement_id == 5, Userachievements.user_id == belikedposts[0][0]).all() if not belikedachievementfirst: belikedachievement = Userachievements(achievement_id=5, user_id=belikedposts[0][0]) belikedpoint = Userpoints(reason='The amount of "Like" reach to 20', points_id=11, user_id=belikedposts[0][0]) db.session.add(belikedachievement) db.session.add(belikedpoint) db.session.commit() if belikedposts[0][1] >= 150: belikedachievementsecond = Userachievements.query.filter(Userachievements.achievement_id == 6, Userachievements.user_id == belikedposts[0][0]).all() if not belikedachievementsecond: belikedachievement = Userachievements(achievement_id=6, user_id=belikedposts[0][0]) belikedpoint = Userpoints(reason='The amount of "Like" reach to 150', points_id=12, user_id=belikedposts[0][0]) db.session.add(belikedachievement) db.session.add(belikedpoint) db.session.commit() return post, belikedposts
def unlikepost_point(pid): reasonunlike = 'Click Not Interested' + ' "' + str(pid) + '"' responsepoints = Userpoints.query.filter( Userpoints.reason == reasonunlike, Userpoints.points_id == 3, Userpoints.user_id == current_user.id).first() if not responsepoints: responserecord = Userpoints(reason='Click Not Interested' + ' "' + str(pid) + '"', points_id=3, user_id=current_user.id) db.session.add(responserecord) db.session.commit() return pid, reasonunlike, responsepoints
def report_achievement(pid): report = Userreport.query.filter_by(report_id=pid).first() reportcount = Userreport.query.filter(Userreport.user_id == report.user_id, Userreport.read == True).count() #print(report) #print(reportcount) reportachievementfirst = Userachievements.query.filter(Userachievements.achievement_id == 13, Userachievements.user_id == report.user_id).all() if reportcount >= 3: if not reportachievementfirst: reportachievement = Userachievements(achievement_id=13, user_id=report.user_id) reportpoint = Userpoints(reason='Report the SE attacks for three times.', points_id=19, user_id=report.user_id) db.session.add(reportachievement) db.session.add(reportpoint) db.session.commit() return report, reportachievementfirst
def beunlikedpost_achievement(pid): post = Post.query.filter_by(post_id=pid).first() beunlikedposts = db.session.query(Post.user_id, func.count(DislikePostRecord.id)).outerjoin(DislikePostRecord, Post.post_id == DislikePostRecord.post_id).group_by(Post.user_id).filter(Post.user_id == post.user_id).all() #print(beunlikedposts) if beunlikedposts[0][1] >= 20: beunlikedachievementfirst = Userachievements.query.filter(Userachievements.achievement_id == 7, Userachievements.user_id == beunlikedposts[0][0]).all() if not beunlikedachievementfirst: beunlikedachievement = Userachievements(achievement_id=7, user_id=beunlikedposts[0][0]) beunlikedpoint = Userpoints(reason='The amount of "Not Interested" reach to 20', points_id=13, user_id=beunlikedposts[0][0]) db.session.add(beunlikedachievement) db.session.add(beunlikedpoint) db.session.commit() if beunlikedposts[0][1] >= 40: beunlikedachievementsecond = Userachievements.query.filter(Userachievements.achievement_id == 8, Userachievements.user_id == beunlikedposts[0][0]).all() if not beunlikedachievementsecond: beunlikedachievement = Userachievements(achievement_id=8, user_id=beunlikedposts[0][0]) beunlikedpoint = Userpoints(reason='The amount of "Not Interested" reach to 40', points_id=14, user_id=beunlikedposts[0][0]) db.session.add(beunlikedachievement) db.session.add(beunlikedpoint) db.session.commit() if beunlikedposts[0][1] >= 200: beunlikedachievementthird = Userachievements.query.filter(Userachievements.achievement_id == 9, Userachievements.user_id == beunlikedposts[0][0]).all() if not beunlikedachievementthird: beunlikedachievement = Userachievements(achievement_id=9, user_id=beunlikedposts[0][0]) beunlikedpoint = Userpoints(reason='The amount of "Not Interested" reach to 200', points_id=15, user_id=beunlikedposts[0][0]) db.session.add(beunlikedachievement) db.session.add(beunlikedpoint) db.session.commit() if beunlikedposts[0][1] >= 400: beunlikedachievementfour = Userachievements.query.filter(Userachievements.achievement_id == 10, Userachievements.user_id == beunlikedposts[0][0]).all() if not beunlikedachievementfour: beunlikedachievement = Userachievements(achievement_id=10, user_id=beunlikedposts[0][0]) beunlikedpoint = Userpoints(reason='The amount of "Not Interested" reach to 400', points_id=16, user_id=beunlikedposts[0][0]) db.session.add(beunlikedachievement) db.session.add(beunlikedpoint) db.session.commit() return post, beunlikedposts
def Click(): log_path = '/var/log/nginx/access.log' clicks = Phishingresult.query.all() for click in clicks: with open(log_path) as log: for line in log: parseRegex = r"GET \/" + re.escape('index') + click.phish_link match = re.search(parseRegex, line) if match: if click.phish_click == False: click.phish_click = True db.session.commit() clickrecord = Userpoints( reason= 'Click the fake hyperlink in phishing simulation' + ' "' + click.campaign.campaign_name + '"', points_id=5, user_id=click.user_id) db.session.add(clickrecord) db.session.commit() return clicks, log_path