1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | def socialAuthenticate(providerId:String) = UserAwareAction.async { implicit request => (socialProviderRegistry.get[SocialProvider](providerId) match { case Some(p:SocialProvider with CommonSocialProfileBuilder) => p.authenticate.flatMap { case Left(result) => Future.successful(result) case Right(authInfo) => for { profile <- p.retrieveProfile(authInfo) user <- request.identity.fold(userService.save(profile))(userService.link(_,profile)) authInfo <- authInfoRepository.save(profile.loginInfo, authInfo) authenticator <- env.authenticatorService.create(profile.loginInfo) value <- env.authenticatorService.init(authenticator) result <- env.authenticatorService.embed(value, Redirect(routes.Application.index())) } yield result } case _ => Future.successful( Redirect(request.identity.fold(routes.Auth.signIn())(_ => routes.Application.profile())) .flashing("error" -> Messages("error.noProvider", providerId)) ) }).recover { case e ![]() logger.error(" ![]() Redirect(request.identity.fold(routes.Auth.signIn())(_ => routes.Application.profile())) .flashing("error" -> Messages("error.notAuthenticated", providerId)) } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |