@@ -29,8 +29,12 @@ var m_current_groupid = null;
29
29
containing as many decoded values as possible. Check isValid for
30
30
complete decode succes. groupId is also set if successful
31
31
/*/
32
- SESUTIL . DecodeToken = function ( token ) {
32
+ SESUTIL . DecodeToken = function ( token , dataset ) {
33
33
if ( token === undefined ) return { } ;
34
+ if ( dataset === undefined ) {
35
+ console . error ( 'SESUTIL.DecodeToken called without "dataset" parameter.' ) ;
36
+ return { } ;
37
+ }
34
38
let tokenBits = token . split ( "-" ) ;
35
39
let classId , projId , hashedId , groupId , subId , isValid ;
36
40
// optimistically set valid flag to be negated on failure
@@ -46,7 +50,7 @@ SESUTIL.DecodeToken = function(token) {
46
50
if ( tokenBits [ 2 ] ) hashedId = tokenBits [ 2 ] . toUpperCase ( ) ;
47
51
if ( tokenBits [ 3 ] ) subId = tokenBits [ 3 ] . toUpperCase ( ) ;
48
52
// initialize hashid structure
49
- let salt = `${ classId } ${ projId } ` ;
53
+ let salt = `${ classId } ${ projId } ${ dataset } ` ;
50
54
let hashids = new HashIds ( salt , HASH_MINLEN , HASH_ABET ) ;
51
55
// try to decode the groupId
52
56
groupId = hashids . decode ( hashedId ) [ 0 ] ;
@@ -88,16 +92,16 @@ SESUTIL.DecodeToken = function(token) {
88
92
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
89
93
/*/ Return TRUE if the token decodes into an expected range of values
90
94
/*/
91
- SESUTIL . IsValidToken = function ( token ) {
92
- let decoded = SESUTIL . DecodeToken ( token ) ;
95
+ SESUTIL . IsValidToken = function ( token , dataset ) {
96
+ let decoded = SESUTIL . DecodeToken ( token , dataset ) ;
93
97
return decoded && Number . isInteger ( decoded . groupId ) ;
94
98
} ;
95
99
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
96
100
/*/ Returns a token string of form CLASS-PROJECT-HASHEDID
97
101
classId and projId should be short and are case-insensitive.
98
102
groupId must be a non-negative integer
99
103
/*/
100
- SESUTIL . MakeToken = function ( classId , projId , groupId ) {
104
+ SESUTIL . MakeToken = function ( classId , projId , groupId , dataset ) {
101
105
// type checking
102
106
if ( typeof classId !== "string" )
103
107
throw Error ( `classId arg1 '${ classId } ' must be string` ) ;
@@ -114,7 +118,7 @@ SESUTIL.MakeToken = function(classId, projId, groupId) {
114
118
// initialize hashid structure
115
119
classId = classId . toUpperCase ( ) ;
116
120
projId = projId . toUpperCase ( ) ;
117
- let salt = `${ classId } ${ projId } ` ;
121
+ let salt = `${ classId } ${ projId } ${ dataset } ` ;
118
122
let hashids = new HashIds ( salt , HASH_MINLEN , HASH_ABET ) ;
119
123
let hashedId = hashids . encode ( groupId ) ;
120
124
return `${ classId } -${ projId } -${ hashedId } ` ;
@@ -124,7 +128,12 @@ SESUTIL.MakeToken = function(classId, projId, groupId) {
124
128
/*/ Set the global GROUPID, which is included in all NetMessage
125
129
packets that are sent to server.
126
130
/*/
127
- SESUTIL . SetGroupID = function ( token ) {
131
+ // REVIEW/FIXME
132
+ // `SetGroupID` isn't being called by anyone?
133
+ // If it is, the DecodeToken call needs to add a 'dataset' parameter or it will
134
+ // fail.
135
+ SESUTIL . SetGroupID = function ( token ) {
136
+ console . error ( 'SetGroupID calling decodeToken NC_CONFIG IS' , window . NC_CONFIG ) ;
128
137
let good = SESUTIL . DecodeToken ( token ) . isValid ;
129
138
if ( good ) m_current_groupid = token ;
130
139
return good ;
0 commit comments