mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-26 09:09:25 +01:00
feat(invitations): exchange an invitation with scores, the invitation can invite friend join us.
This commit is contained in:
@@ -419,6 +419,13 @@
|
||||
HOW_TO_GET_LEVEL: 'How to count user level?',
|
||||
HOW_TO_GET_SCORE: 'How to get score number?'
|
||||
},
|
||||
EXCHANGE_INVITATION: 'Exchange an invitation ({{score}} scores)',
|
||||
EXCHANGE_INVITATION_CONFIRM_OK: 'Exchange',
|
||||
EXCHANGE_INVITATION_CONFIRM_CANCEL: 'Cancel',
|
||||
EXCHANGE_INVITATION_CONFIRM_HEADER_TEXT: 'Exchange Confirm',
|
||||
EXCHANGE_INVITATION_CONFIRM_BODY_TEXT: 'Are you sure want to exchange an invitation with {{score}} scores?',
|
||||
EXCHANGE_INVITATION_SUCCESSFULLY: 'Exchange invitation successfully',
|
||||
EXCHANGE_INVITATION_ERROR: 'Exchange invitation failed',
|
||||
|
||||
//user message box
|
||||
MESSAGES_INBOX: 'Messages Inbox',
|
||||
|
||||
@@ -419,6 +419,13 @@
|
||||
HOW_TO_GET_LEVEL: '怎么计算用户级别?',
|
||||
HOW_TO_GET_SCORE: '怎么取得用户积分?'
|
||||
},
|
||||
EXCHANGE_INVITATION: '兑换一个邀请 ({{score}} 积分)',
|
||||
EXCHANGE_INVITATION_CONFIRM_OK: '兑换',
|
||||
EXCHANGE_INVITATION_CONFIRM_CANCEL: '取消',
|
||||
EXCHANGE_INVITATION_CONFIRM_HEADER_TEXT: '兑换确认',
|
||||
EXCHANGE_INVITATION_CONFIRM_BODY_TEXT: '您确定要花 {{score}} 积分来兑换一个限时邀请么?',
|
||||
EXCHANGE_INVITATION_SUCCESSFULLY: '限时邀请兑换成功',
|
||||
EXCHANGE_INVITATION_ERROR: '限时邀请兑换失败',
|
||||
|
||||
//user message box
|
||||
MESSAGES_INBOX: '消息收件箱',
|
||||
|
||||
@@ -26,6 +26,11 @@
|
||||
|
||||
$scope.$on('$stateChangeSuccess', stateChangeSuccess);
|
||||
|
||||
$scope.$on('auth-user-score-changed', function(event, args) {
|
||||
vm.user = Authentication.user;
|
||||
vm.scoreLevelData = vm.user ? ScoreLevelService.getScoreLevelJson(vm.user.score) : undefined;
|
||||
});
|
||||
|
||||
function stateChangeSuccess() {
|
||||
// Collapsing the menu after navigation
|
||||
vm.isCollapsed = false;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
function link(scope, element, attrs) {
|
||||
scope.$watch(attrs.scoreLevel, function (level) {
|
||||
console.log('level changed to ' + level);
|
||||
|
||||
var l = 'L' + (level ? level : 0);
|
||||
l = '<kbd>' + l + '</kbd>';
|
||||
|
||||
|
||||
@@ -27,7 +27,21 @@ exports.create = function (req, res) {
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
res.json(invitation);
|
||||
//res.json(invitation);
|
||||
var user = req.user;
|
||||
user.update({
|
||||
$set: {score: user.score - config.meanTorrentConfig.invite.score_exchange}
|
||||
}).exec(function (err, result) {
|
||||
if (err) {
|
||||
return res.status(422).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
user.score = user.score - config.meanTorrentConfig.invite.score_exchange;
|
||||
res.json(user);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -7,13 +7,6 @@ var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema,
|
||||
validator = require('validator');
|
||||
|
||||
/**
|
||||
* A Validation function for local strategy email
|
||||
*/
|
||||
var validateLocalStrategyEmail = function (email) {
|
||||
return validator.isEmail(email, {require_tld: false});
|
||||
};
|
||||
|
||||
/**
|
||||
* Peer Schema
|
||||
*/
|
||||
@@ -28,12 +21,11 @@ var InvitationSchema = new Schema({
|
||||
},
|
||||
to_email: {
|
||||
type: String,
|
||||
unique: 'email already exists',
|
||||
required: 'Please fill in a email address',
|
||||
//unique: 'email already exists',
|
||||
//required: 'Please fill in a email address',
|
||||
lowercase: true,
|
||||
trim: true,
|
||||
default: '',
|
||||
validate: [validateLocalStrategyEmail, 'Please fill a valid email address']
|
||||
default: ''
|
||||
},
|
||||
status: {
|
||||
type: Number,
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
.module('users')
|
||||
.controller('ScoreController', ScoreController);
|
||||
|
||||
ScoreController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', '$window', 'ScoreLevelService', 'getStorageLangService',
|
||||
'MeanTorrentConfig'];
|
||||
ScoreController.$inject = ['$rootScope', '$scope', '$state', '$translate', '$timeout', 'Authentication', '$window', 'ScoreLevelService', 'getStorageLangService',
|
||||
'MeanTorrentConfig', 'ModalConfirmService', 'NotifycationService', 'InvitationsService'];
|
||||
|
||||
function ScoreController($scope, $state, $translate, $timeout, Authentication, $window, ScoreLevelService, getStorageLangService, MeanTorrentConfig) {
|
||||
function ScoreController($rootScope, $scope, $state, $translate, $timeout, Authentication, $window, ScoreLevelService, getStorageLangService, MeanTorrentConfig,
|
||||
ModalConfirmService, NotifycationService, InvitationsService) {
|
||||
var vm = this;
|
||||
vm.scoreConfig = MeanTorrentConfig.meanTorrentConfig.score;
|
||||
|
||||
vm.inviteConfig = MeanTorrentConfig.meanTorrentConfig.invite;
|
||||
vm.lang = getStorageLangService.getLang();
|
||||
vm.user = Authentication.user;
|
||||
|
||||
@@ -22,11 +23,51 @@
|
||||
$state.go('authentication.signin');
|
||||
}
|
||||
|
||||
$scope.$on('auth-user-score-changed', function(event, args) {
|
||||
vm.user = Authentication.user;
|
||||
vm.scoreLevelData = vm.user ? ScoreLevelService.getScoreLevelJson(vm.user.score) : undefined;
|
||||
});
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
vm.init = function () {
|
||||
vm.scoreLevelData = ScoreLevelService.getScoreLevelJson(vm.user.score);
|
||||
};
|
||||
|
||||
/**
|
||||
* exchangeInvitation
|
||||
*/
|
||||
vm.exchangeInvitation = function () {
|
||||
var modalOptions = {
|
||||
closeButtonText: $translate.instant('EXCHANGE_INVITATION_CONFIRM_CANCEL'),
|
||||
actionButtonText: $translate.instant('EXCHANGE_INVITATION_CONFIRM_OK'),
|
||||
headerText: $translate.instant('EXCHANGE_INVITATION_CONFIRM_HEADER_TEXT'),
|
||||
bodyText: $translate.instant('EXCHANGE_INVITATION_CONFIRM_BODY_TEXT', {score: vm.inviteConfig.score_exchange})
|
||||
};
|
||||
|
||||
ModalConfirmService.showModal({}, modalOptions)
|
||||
.then(function (result) {
|
||||
var invitation = new InvitationsService();
|
||||
|
||||
invitation.$save(function (response) {
|
||||
successCallback(response);
|
||||
}, function (errorResponse) {
|
||||
errorCallback(errorResponse);
|
||||
});
|
||||
|
||||
function successCallback(res) {
|
||||
if (res._id === vm.user._id) {
|
||||
vm.user = Authentication.user = res;
|
||||
$rootScope.$broadcast('auth-user-score-changed');
|
||||
}
|
||||
NotifycationService.showSuccessNotify('EXCHANGE_INVITATION_SUCCESSFULLY');
|
||||
}
|
||||
|
||||
function errorCallback(res) {
|
||||
NotifycationService.showErrorNotify(res.data.message, 'EXCHANGE_INVITATION_ERROR');
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -23,6 +23,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row margin-top-30">
|
||||
<div class="col-sm-8 col-sm-offset-2 text-center">
|
||||
<button class="btn btn-default" ng-disabled="vm.user.score < vm.inviteConfig.score_exchange"
|
||||
translate="EXCHANGE_INVITATION" translate-values='{ score: vm.inviteConfig.score_exchange}'
|
||||
ng-click="vm.exchangeInvitation();">
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row margin-top-30 padding-top-30">
|
||||
<div class="col-sm-8 col-sm-offset-2">
|
||||
<legend class="small-legend" translate="SCORE.HOW_TO_GET_LEVEL"></legend>
|
||||
|
||||
Reference in New Issue
Block a user