Merge branch 'master' of https://bitbucket.org/yackob03/quay
This commit is contained in:
commit
8c92230b71
3 changed files with 63 additions and 20 deletions
|
@ -40,6 +40,10 @@ def api_login_required(f):
|
||||||
def decorated_view(*args, **kwargs):
|
def decorated_view(*args, **kwargs):
|
||||||
if not current_user.is_authenticated():
|
if not current_user.is_authenticated():
|
||||||
abort(401)
|
abort(401)
|
||||||
|
|
||||||
|
if current_user and current_user.db_user() and current_user.db_user().organization:
|
||||||
|
abort(401)
|
||||||
|
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
return decorated_view
|
return decorated_view
|
||||||
|
|
||||||
|
@ -82,6 +86,9 @@ def get_logged_in_user():
|
||||||
return jsonify({'anonymous': True})
|
return jsonify({'anonymous': True})
|
||||||
|
|
||||||
user = current_user.db_user()
|
user = current_user.db_user()
|
||||||
|
if not user or user.organization:
|
||||||
|
return jsonify({'anonymous': True})
|
||||||
|
|
||||||
organizations = model.get_user_organizations(user.username)
|
organizations = model.get_user_organizations(user.username)
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
|
@ -223,9 +230,7 @@ def conduct_signin(username, password):
|
||||||
@api_login_required
|
@api_login_required
|
||||||
def logout():
|
def logout():
|
||||||
logout_user()
|
logout_user()
|
||||||
|
|
||||||
identity_changed.send(app, identity=AnonymousIdentity())
|
identity_changed.send(app, identity=AnonymousIdentity())
|
||||||
|
|
||||||
return make_response('Success', 200)
|
return make_response('Success', 200)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1190,7 +1195,8 @@ def subscribe_api():
|
||||||
token = request_data['token'] if 'token' in request_data else None
|
token = request_data['token'] if 'token' in request_data else None
|
||||||
user = current_user.db_user()
|
user = current_user.db_user()
|
||||||
return subscribe(user, plan, token, USER_PLANS)
|
return subscribe(user, plan, token, USER_PLANS)
|
||||||
|
|
||||||
|
|
||||||
def subscribe(user, plan, token, accepted_plans):
|
def subscribe(user, plan, token, accepted_plans):
|
||||||
plan_found = None
|
plan_found = None
|
||||||
for plan_obj in accepted_plans:
|
for plan_obj in accepted_plans:
|
||||||
|
@ -1202,16 +1208,25 @@ def subscribe(user, plan, token, accepted_plans):
|
||||||
|
|
||||||
private_repos = model.get_private_repo_count(user.username)
|
private_repos = model.get_private_repo_count(user.username)
|
||||||
|
|
||||||
if not user.stripe_id:
|
# This is the default response
|
||||||
# Create the customer and plan simultaneously
|
response_json = {
|
||||||
card = token
|
'plan': plan,
|
||||||
cus = stripe.Customer.create(email=user.email, plan=plan, card=card)
|
'usedPrivateRepos': private_repos,
|
||||||
user.stripe_id = cus.id
|
}
|
||||||
user.save()
|
status_code = 200
|
||||||
|
|
||||||
resp = jsonify(subscription_view(cus.subscription, private_repos))
|
if not user.stripe_id:
|
||||||
resp.status_code = 201
|
# Check if a non-paying user is trying to subscribe to a free plan
|
||||||
return resp
|
if not plan_found['price'] == 0:
|
||||||
|
# They want a real paying plan, create the customerand plan
|
||||||
|
# simultaneously
|
||||||
|
card = token
|
||||||
|
cus = stripe.Customer.create(email=user.email, plan=plan, card=card)
|
||||||
|
user.stripe_id = cus.id
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
response_json = subscription_view(cus.subscription, private_repos)
|
||||||
|
status_code = 201
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Change the plan
|
# Change the plan
|
||||||
|
@ -1223,11 +1238,6 @@ def subscribe(user, plan, token, accepted_plans):
|
||||||
cus.cancel_subscription()
|
cus.cancel_subscription()
|
||||||
cus.save()
|
cus.save()
|
||||||
|
|
||||||
response_json = {
|
|
||||||
'plan': plan,
|
|
||||||
'usedPrivateRepos': private_repos,
|
|
||||||
}
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
cus.plan = plan
|
cus.plan = plan
|
||||||
# User may have been a previous customer who is resubscribing
|
# User may have been a previous customer who is resubscribing
|
||||||
|
@ -1237,7 +1247,9 @@ def subscribe(user, plan, token, accepted_plans):
|
||||||
cus.save()
|
cus.save()
|
||||||
response_json = subscription_view(cus.subscription, private_repos)
|
response_json = subscription_view(cus.subscription, private_repos)
|
||||||
|
|
||||||
return jsonify(response_json)
|
resp = jsonify(response_json)
|
||||||
|
resp.status_code = status_code
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/organization/<orgname>/plan', methods=['PUT'])
|
@app.route('/api/organization/<orgname>/plan', methods=['PUT'])
|
||||||
|
|
|
@ -60,7 +60,7 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
|
||||||
|
|
||||||
var userService = {}
|
var userService = {}
|
||||||
|
|
||||||
userService.load = function() {
|
userService.load = function(opt_callback) {
|
||||||
var userFetch = Restangular.one('user/');
|
var userFetch = Restangular.one('user/');
|
||||||
userFetch.get().then(function(loadedUser) {
|
userFetch.get().then(function(loadedUser) {
|
||||||
userResponse = loadedUser;
|
userResponse = loadedUser;
|
||||||
|
@ -76,6 +76,10 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
|
||||||
'$created': new Date()
|
'$created': new Date()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opt_callback) {
|
||||||
|
opt_callback();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -867,7 +871,16 @@ quayApp.directive('ngBlur', function() {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
quayApp.run(['$location', '$rootScope', function($location, $rootScope) {
|
quayApp.run(['$location', '$rootScope', 'Restangular', 'UserService', function($location, $rootScope, Restangular, UserService) {
|
||||||
|
Restangular.setErrorInterceptor(function(response) {
|
||||||
|
if (response.status == 401) {
|
||||||
|
$('#sessionexpiredModal').modal({});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
|
$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
|
||||||
if (current.$$route.title) {
|
if (current.$$route.title) {
|
||||||
$rootScope.title = current.$$route.title;
|
$rootScope.title = current.$$route.title;
|
||||||
|
|
|
@ -30,4 +30,22 @@
|
||||||
|
|
||||||
{% block body_content %}
|
{% block body_content %}
|
||||||
<div ng-view></div>
|
<div ng-view></div>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Modal message dialog -->
|
||||||
|
<div class="modal fade" id="sessionexpiredModal" data-backdrop="static">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h4 class="modal-title">Session Expired</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
Your user session has expired. Please reload to continue.
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
</div>
|
||||||
|
</div><!-- /.modal-content -->
|
||||||
|
</div><!-- /.modal-dialog -->
|
||||||
|
</div><!-- /.modal -->
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Reference in a new issue