Beispiel #1
0
def like_user_ajax():
    req = request.get_json() if request.is_json else request.form
    try:
        user = Account(session['user'])
        recipient = Account(req['liked_user'])
        action = user.like_user(recipient)
        Notification.send(user, recipient, action)
    except KeyError:
        return jsonify({'success': False, 'error': 'KeyError'})
    except Exception as e:
        return jsonify({'success': False, 'error': str(e)})
    return jsonify({'success': True, 'unlike': bool(action == 'unlike')})
Beispiel #2
0
def like_user(user_id):
    try:
        user = Account(session['user'])
        recipient = Account(user_id)
        action = user.like_user(recipient)
        if action == 'like':
            msg = "Your liked was received. If you get liked back, you'll be able to chat"
        elif action == 'like_back':
            msg = "Great! You can chat now."
        else:
            msg = "You successfully disconnected from that user."
        flash(msg, 'success')
        Notification.send(user, recipient, action)
    except Exception as e:
        flash(str(e), 'danger')
    return redirect(url_for('profile', user_id=user_id))