forked from vazco/meteor-universe-accounts-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.import.js
63 lines (59 loc) · 2.04 KB
/
utils.import.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
export default {
capitalize (string) {
return string.charAt(0).toUpperCase() + string.slice(1);
},
currentUser () {
if (typeof ReactionCore === "object") {
// shoppers should always be guests
const isGuest = Roles.userIsInRole(Meteor.user(), "guest", ReactionCore
.getShopId());
// but if a user has never logged in then they are anonymous
const isAnonymous = Roles.userIsInRole(Meteor.user(), "anonymous",
ReactionCore.getShopId());
return isGuest && !isAnonymous ? Meteor.user() : null;
//if (!isGuest && isAnonymous) {
// return null;
//} else if (isGuest && !isAnonymous) {
// return Meteor.user();
//}
//return null;
}
},
getServiceNames () {
if (!Package['accounts-oauth']) {
// no oauth package so no services
return [];
}
return Accounts.oauth.serviceNames().sort();
},
hasPasswordService () {
return !!Package['accounts-password'];
},
performOAuthLogin (service, cb) {
try {
// @todo this can be done better, multi word services may not work
// @todo options need to passed from Accounts.ui.config
Meteor[`loginWith${this.capitalize(service)}`]({}, cb);
} catch (e) {
cb(e);
}
},
onError(error) {
// todo don't know how to handle situation then "is required" error
// was happen and after field was filled other error happens in same
// field
// this is more looks like client-side validation logic. We take
// away this part temporary
/*let errors = this.state.errors;
if (~~errors.indexOf(error)) {
errors.push(error);
this.setState({ errors: errors });
}*/
let errors = [];
errors.push(error);
this.setState({ errors: errors });
},
clearErrors() {
this.setState({ errors: [] });
}
};