Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Moecube Accounts Web
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Moecube Accounts Web
Commits
a4d9fd27
Commit
a4d9fd27
authored
Apr 06, 2017
by
2breakegg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
error.messages
parent
96f13a64
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
169 additions
and
149 deletions
+169
-149
src/models/auth.js
src/models/auth.js
+53
-40
src/models/user.js
src/models/user.js
+116
-109
No files found.
src/models/auth.js
View file @
a4d9fd27
import
{
login
,
forgot
,
register
,
reset
,
activate
,
checkUserExists
}
from
'
../services/auth
'
import
{
message
}
from
'
antd
'
import
{
routerRedux
}
from
'
dva/router
'
import
config
from
'
../config
'
import
{
message
}
from
'
antd
'
;
import
{
routerRedux
}
from
'
dva/router
'
;
import
{
activate
,
checkUserExists
,
forgot
,
login
,
register
,
reset
}
from
'
../services/auth
'
;
export
default
{
...
...
@@ -30,23 +28,26 @@ export default {
},
checkEmail
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
checkEmail
:
'
validating
'
,
}
}
,
};
},
checkUsername
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
checkUsername
:
'
validating
'
,
}
}
,
};
},
activate
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
activateState
:
true
,
}
}
,
};
},
check
(
state
,
action
)
{
...
...
@@ -56,86 +57,99 @@ export default {
},
register
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
isRegisterSubmit
:
true
,
}
};
},
registerSuccess
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
isRegisterSubmit
:
false
,
}
}
,
};
},
registerFail
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
isRegisterSubmit
:
false
,
}
}
,
};
},
login
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
isLoginSubmit
:
true
,
}
}
,
};
},
loginSuccess
(
state
,
action
)
{
return
{
...
state
,
...
action
.
payload
,
...{
...
state
,
...
action
.
payload
,
...{
isLoginSubmit
:
false
,
}
}
,
};
},
loginFail
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
isLoginSubmit
:
false
,
}
}
,
};
},
forgot
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
isForgotSubmit
:
true
,
}
}
,
};
},
forgotSuccess
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
isForgotSubmit
:
false
,
}
}
,
};
},
forgotFail
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
isForgotSubmit
:
false
,
}
}
,
};
},
reset
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
isResetSubmit
:
true
,
}
}
,
};
},
resetSuccess
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
isResetSubmit
:
false
,
}
}
,
};
},
resetFail
(
state
,
action
)
{
return
{
...
state
,
...{
...
state
,
...{
isResetSubmit
:
false
,
}
}
,
};
},
},
...
...
@@ -193,7 +207,7 @@ export default {
}
}
catch
(
error
)
{
yield
put
({
type
:
'
loginFail
'
});
message
.
error
(
messages
[
error
.
message
]);
message
.
error
(
messages
[
error
.
message
]
||
error
.
message
);
}
},
*
forgot
({
payload
},
{
call
,
put
,
select
})
{
...
...
@@ -206,7 +220,7 @@ export default {
}
}
catch
(
error
)
{
yield
put
({
type
:
'
forgotFail
'
});
message
.
error
(
messages
[
error
.
message
],
3
);
message
.
error
(
messages
[
error
.
message
]
||
error
.
message
,
3
);
}
},
*
register
({
payload
},
{
call
,
put
,
select
})
{
...
...
@@ -223,7 +237,7 @@ export default {
}
}
catch
(
error
)
{
yield
put
({
type
:
'
registerFail
'
});
message
.
error
(
messages
[
error
.
message
],
3
);
message
.
error
(
messages
[
error
.
message
]
||
error
.
message
,
3
);
}
},
*
reset
({
payload
},
{
call
,
put
,
select
})
{
...
...
@@ -236,10 +250,9 @@ export default {
}
}
catch
(
error
)
{
yield
put
({
type
:
'
resetFail
'
});
message
.
error
(
messages
[
error
.
message
],
3
);
message
.
error
(
messages
[
error
.
message
]
||
error
.
message
,
3
);
}
},
},
subscriptions
:
{
}
subscriptions
:
{},
};
src/models/user.js
View file @
a4d9fd27
import
{
routerRedux
}
from
'
dva/router
'
import
{
updateProfile
,
updateAccount
}
from
'
../services/user
'
import
{
getAuthUser
}
from
'
../services/auth
'
import
{
message
}
from
'
antd
'
import
{
handleSSO
}
from
'
../utils/sso
'
import
{
message
}
from
'
antd
'
;
import
{
routerRedux
}
from
'
dva/router
'
;
import
{
getAuthUser
}
from
'
../services/auth
'
;
import
{
updateAccount
,
updateProfile
}
from
'
../services/user
'
;
import
{
handleSSO
}
from
'
../utils/sso
'
;
export
default
{
namespace
:
'
user
'
,
state
:
{
token
:
""
,
token
:
''
,
user
:
{},
isUpdateSubmit
:
false
isUpdateSubmit
:
false
,
},
reducers
:
{
loginFromStorage
(
state
,
action
)
{
return
{
...
state
,
...
action
.
payload
}
}
;
},
loginSuccess
(
state
,
action
)
{
return
{
...
state
,
...
action
.
payload
.
data
}
}
;
},
updateProfile
(
state
,
action
)
{
return
{
...
state
,
...{
isUpdateSubmit
:
true
}
}
...
state
,
...{
isUpdateSubmit
:
true
,
},
};
},
updateProfileSuccess
(
state
,
action
)
{
return
{
...
state
,
...
action
.
payload
,
...{
isUpdateSubmit
:
false
}
}
...
state
,
...
action
.
payload
,
...{
isUpdateSubmit
:
false
,
},
};
},
updateProfileFail
(
state
,
action
)
{
return
{
...
state
,
...{
isUpdateSubmit
:
false
}
}
...
state
,
...{
isUpdateSubmit
:
false
,
},
};
},
updateAccount
(
state
,
action
)
{
return
{
...
state
,
...{
isUpdateSubmit
:
true
}
}
...
state
,
...{
isUpdateSubmit
:
true
,
},
};
},
updateAccountSuccess
(
state
,
action
)
{
return
{
...
state
,
...
action
.
payload
,
...{
isUpdateSubmit
:
false
}
}
...
state
,
...
action
.
payload
,
...{
isUpdateSubmit
:
false
,
},
};
},
updateAccountFail
(
state
,
action
)
{
return
{
...
state
,
...{
isUpdateSubmit
:
false
}
}
...
state
,
...{
isUpdateSubmit
:
false
,
},
};
},
storeToken
(
state
,
action
)
{
return
{
...
state
,
...
action
.
payload
}
...
state
,
...
action
.
payload
,
}
;
},
preLoginSuccess
(
state
,
action
)
{
return
{
...
state
,
...
action
.
payload
}
...
state
,
...
action
.
payload
,
}
;
},
getAuthUserSuccess
(
state
,
action
)
{
return
{
...
state
,
...
action
.
payload
}
}
...
state
,
...
action
.
payload
,
}
;
}
,
},
effects
:
{
*
loginSuccess
({
payload
},
{
call
,
put
})
{
const
{
data
:
{
user
,
token
}
}
=
payload
const
{
data
:
{
user
,
token
}
}
=
payload
;
if
(
!
payload
.
data
)
{
message
.
error
(
"
error
"
)
if
(
!
payload
.
data
)
{
message
.
error
(
'
error
'
);
}
if
(
token
)
{
yield
put
({
type
:
'
storeToken
'
,
payload
:
{
token
}
})
localStorage
.
setItem
(
"
token
"
,
token
)
if
(
token
)
{
yield
put
({
type
:
'
storeToken
'
,
payload
:
{
token
}
});
localStorage
.
setItem
(
'
token
'
,
token
);
}
if
(
user
)
{
if
(
handleSSO
(
user
))
{
return
if
(
user
)
{
if
(
handleSSO
(
user
))
{
return
;
}
if
(
user
.
active
)
{
yield
put
(
routerRedux
.
replace
(
"
/profiles
"
))
// message.info("登录成功")
if
(
user
.
active
)
{
yield
put
(
routerRedux
.
replace
(
'
/profiles
'
));
// message.info("登录成功")
}
else
{
yield
put
(
routerRedux
.
replace
(
`/verify`
))
yield
put
(
routerRedux
.
replace
(
'
/verify
'
));
}
}
},
*
getAuthUser
({
payload
},
{
call
,
put
,
select
})
{
const
{
token
}
=
payload
const
{
token
}
=
payload
;
try
{
let
{
data
}
=
yield
call
(
getAuthUser
,
{
token
})
if
(
data
)
{
yield
put
({
type
:
'
getAuthUserSuccess
'
,
payload
:
{
user
:
data
,
token
}
})
}
}
catch
(
error
)
{
message
.
error
(
error
.
message
)
let
{
data
}
=
yield
call
(
getAuthUser
,
{
token
});
if
(
data
)
{
yield
put
({
type
:
'
getAuthUserSuccess
'
,
payload
:
{
user
:
data
,
token
}
});
}
}
catch
(
error
)
{
message
.
error
(
error
.
message
)
;
}
},
*
preLogin
({
payload
},
{
call
,
put
,
select
})
{
const
{
token
}
=
payload
if
(
!
token
)
{
yield
put
(
routerRedux
.
replace
(
"
/signin
"
))
const
{
token
}
=
payload
;
if
(
!
token
)
{
yield
put
(
routerRedux
.
replace
(
'
/signin
'
));
}
try
{
let
{
data
}
=
yield
call
(
getAuthUser
,
{
token
})
let
{
data
}
=
yield
call
(
getAuthUser
,
{
token
});
if
(
data
)
{
if
(
handleSSO
(
data
))
{
return
}
if
(
data
.
active
)
{
yield
put
(
routerRedux
.
replace
(
"
/profiles
"
))
}
else
{
yield
put
(
routerRedux
.
replace
(
"
/verify
"
))
}
}
if
(
handleSSO
(
data
))
{
return
;
}
if
(
data
.
active
)
{
yield
put
(
routerRedux
.
replace
(
'
/profiles
'
));
}
else
{
yield
put
(
routerRedux
.
replace
(
'
/verify
'
));
}
}
}
catch
(
error
)
{
yield
put
(
routerRedux
.
replace
(
"
/signin
"
))
message
.
error
(
error
.
message
)
yield
put
(
routerRedux
.
replace
(
'
/signin
'
));
message
.
error
(
error
.
message
)
;
}
},
*
updateProfile
({
payload
},
{
call
,
put
,
select
})
{
message
.
destroy
()
message
.
destroy
()
;
let
token
=
yield
select
(
state
=>
state
.
user
.
token
)
let
{
messages
}
=
yield
select
(
state
=>
state
.
common
)
let
token
=
yield
select
(
state
=>
state
.
user
.
token
)
;
let
{
messages
}
=
yield
select
(
state
=>
state
.
common
)
;
try
{
let
{
data
}
=
yield
call
(
updateProfile
,
{
...
payload
,
token
})
let
{
data
}
=
yield
call
(
updateProfile
,
{
...
payload
,
token
});
if
(
data
)
{
yield
put
({
type
:
'
updateProfileSuccess
'
,
payload
:
{
user
:
data
,
token
}
})
yield
put
({
type
:
'
updateProfileSuccess
'
,
payload
:
{
user
:
data
,
token
}
})
;
message
.
info
(
messages
[
"
update_success
"
])
message
.
info
(
messages
.
update_success
);
}
}
catch
(
error
)
{
yield
put
({
type
:
'
updateProfileFail
'
})
message
.
error
(
error
.
message
)
yield
put
({
type
:
'
updateProfileFail
'
})
;
message
.
error
(
error
.
message
)
;
}
},
*
updateEmail
({
payload
},
{
call
,
put
,
select
})
{
let
{
messages
}
=
yield
select
(
state
=>
state
.
common
)
let
{
messages
}
=
yield
select
(
state
=>
state
.
common
)
;
try
{
let
token
=
yield
select
(
state
=>
state
.
user
.
token
)
let
{
data
}
=
yield
call
(
updateAccount
,
{
...
payload
,
token
})
let
token
=
yield
select
(
state
=>
state
.
user
.
token
)
;
let
{
data
}
=
yield
call
(
updateAccount
,
{
...
payload
,
token
});
if
(
data
)
{
yield
put
({
type
:
'
updateAccountSuccess
'
,
payload
:
{
user
:
data
,
token
}
})
message
.
info
(
messages
[
'
A-verification-email-has-been-sent-to-you,please-check-the-mail-to-complete.
'
])
yield
put
({
type
:
'
updateAccountSuccess
'
,
payload
:
{
user
:
data
,
token
}
})
;
message
.
info
(
messages
[
'
A-verification-email-has-been-sent-to-you,please-check-the-mail-to-complete.
'
])
;
}
}
catch
(
error
)
{
yield
put
({
type
:
'
updateAccountFail
'
})
message
.
error
(
messages
[
error
.
message
]
)
yield
put
({
type
:
'
updateAccountFail
'
})
;
message
.
error
(
messages
[
error
.
message
]
||
error
.
message
);
}
},
*
updateAccount
({
payload
},
{
call
,
put
,
select
})
{
let
{
messages
}
=
yield
select
(
state
=>
state
.
common
)
let
{
messages
}
=
yield
select
(
state
=>
state
.
common
)
;
try
{
let
token
=
yield
select
(
state
=>
state
.
user
.
token
)
let
{
data
}
=
yield
call
(
updateAccount
,
{
...
payload
,
token
})
let
token
=
yield
select
(
state
=>
state
.
user
.
token
)
;
let
{
data
}
=
yield
call
(
updateAccount
,
{
...
payload
,
token
});
if
(
data
)
{
yield
put
({
type
:
'
updateAccountSuccess
'
,
payload
:
{
user
:
data
,
token
}
})
message
.
info
(
messages
[
"
update_success
"
])
yield
put
({
type
:
'
updateAccountSuccess
'
,
payload
:
{
user
:
data
,
token
}
})
;
message
.
info
(
messages
.
update_success
);
}
}
catch
(
error
)
{
yield
put
({
type
:
'
updateAccountFail
'
})
message
.
error
(
messages
[
error
.
message
]
)
yield
put
({
type
:
'
updateAccountFail
'
})
;
message
.
error
(
messages
[
error
.
message
]
||
error
.
message
);
}
},
},
subscriptions
:
{
setup
({
dispatch
,
history
})
{
let
token
=
localStorage
.
getItem
(
"
token
"
)
let
token
=
localStorage
.
getItem
(
'
token
'
);
if
(
token
)
{
dispatch
({
type
:
'
getAuthUser
'
,
payload
:
{
token
}})
dispatch
({
type
:
'
getAuthUser
'
,
payload
:
{
token
}
});
}
history
.
listen
(({
pathname
,
query
})
=>
{
if
(
pathname
==
'
/
'
)
{
dispatch
({
type
:
'
preLogin
'
,
payload
:
{
token
}
})
if
(
pathname
==
'
/
'
)
{
dispatch
({
type
:
'
preLogin
'
,
payload
:
{
token
}
})
;
}
})
}
})
;
}
,
},
};
\ No newline at end of file
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment