예제 #1
0
파일: routes.py 프로젝트: younghai/Pager
	def on_create_room(self, raw_attendees, user):
		chat_room = ChatRoom()
		chat_room.creator = user
		for raw_attendee in raw_attendees:
			attendee_id = raw_attendee.get('id', None)
			if attendee_id:
				attendee = User.get(attendee_id)
			elif raw_attendee['type'] == 'facebook':
				# TODO race condition may occurs need cacth exceptions
				attendee = User.get_by_facebook(raw_attendee['uid'])
				if not attendee:
					attendee = User()
					facebook_account = attendee.facebook_account =\
						FacebookAccount()
					facebook_account.name = attendee.nickname =\
						raw_attendee['nickname']
					attendee.email = raw_attendee.get('email', None)
					facebook_account.uid = raw_attendee['uid']
					db.session.add(attendee)
					db.session.commit()
			else:
				# TODO email account?
				pass
			chat_room.users.append(attendee)
		db.session.add(chat_room)
		db.session.commit()
		json = chat_room.to_json()
		json['message'] = chat_room.messages.first()
		return None, chat_room.to_json()
예제 #2
0
파일: routes.py 프로젝트: younghai/Pager
	def decorated(self, *args, **kwargs):
		user_id = self.session.get('user_id', None)
		user = user_id and User.get(user_id) or None
		if not user:
			return 403, 
		kwargs['user'] = user
		return f(self, *args, **kwargs)
예제 #3
0
파일: routes.py 프로젝트: younghai/Pager
	def on_authenticate_facebook(self, response):
		try:
			access_token, expires_in = \
				response['accessToken'], response['expiresIn']
			signed_request = parse_signed_request(
				response['signedRequest'], app.config['FACEBOOK_SECRET'],
				expires_in
			)
			if not signed_request:
				return None, None
			graph = GraphAPI(access_token)
			profile = graph.get_object('me')
			user = User.get_by_facebook(profile['id'])
			if not user or user.status == User.NOT_REGISTERED_YET:
				if not user:
					user = User()
					user.facebook_account = FacebookAccount()
				user.email = profile['email']
				user.facebook_account.name = user.nickname = profile['name']
				user.facebook_account.uid = profile['id']
				user.status = User.NORMAL
				db.session.add(user)
				db.session.commit()
			self.online_users[self] = self.session['user_id'] = user.id
			self.facebook_access_token = access_token, signed_request['expires_at']
			return None, user.to_json()
		except GraphAPIError, e:
			return {'_type': 'GraphAPIError', 'msg': str(GraphAPIError)},
예제 #4
0
파일: routes.py 프로젝트: younghai/Pager
def process_params(endpoint, values):
    try:
    	if values:
	        if 'user_id' in values:
	        	id = values.pop('user_id', None)
	        	if id:
	        		user = User.query.filter_by(id=id).one()
	        	else:
	        		user = User()
	        	values['user'] = user
	       	if 'message' in values:
	       		id = values.get('message', None)
	       		if id:
	       			message = Message.query.filter_by(id=id).one()
	       		else:
	       			message = Message()
	       		values['message'] = message
    except NoResultFound:
        abort(404)
예제 #5
0
파일: tasks.py 프로젝트: rubythonode/Pager
def send_notify_mails(limit=0):
    smtp = SMTP(config.SMTP_SERVER)
    try:
        with app.test_request_context(base_url=config.BASE_URL):
            query = User.query_has_absence_mail_message_logs()
            if limit > 0:
                query = query.limit(limit)
            for user in query:
                message_logs = tuple(
                    user.absence_mail_message_logs.options(
                        db.joinedload(MessageLog.message), db.joinedload(MessageLog.message, Message.user)
                    )
                )
                send_notify_mail(user, message_logs, smtp)
                for ml in message_logs:
                    ml.mark_notified()
                db.session.commit()
    finally:
        smtp.quit()
        send_notify_mails.apply_async(countdown=60)
예제 #6
0
파일: admin.py 프로젝트: baboleevan/Pager
def list_absence_emails():
    test_email=request.values.get('test_email', '')
    users = User.query_has_absence_mail_message_logs()
    return dict(users=users, test_email=test_email)
예제 #7
0
def list_absence_emails():
    test_email = request.values.get('test_email', '')
    users = User.query_has_absence_mail_message_logs()
    return dict(users=users, test_email=test_email)