本文整理汇总了Scala中com.mohiva.play.silhouette.api.Environment类的典型用法代码示例。如果您正苦于以下问题:Scala Environment类的具体用法?Scala Environment怎么用?Scala Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Environment类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: CoinController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import com.mohiva.play.silhouette.api.{Environment, Silhouette}
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import forms.CoinAddForm
import models.User
import models.coin.{Person, WorkEntry}
import models.common.Pagination
import play.api.i18n.MessagesApi
import play.api.mvc.{Action, AnyContent}
import scala.concurrent.Future
class CoinController @Inject()(
val messagesApi: MessagesApi,
val env: Environment[User, CookieAuthenticator]
) extends Silhouette[User, CookieAuthenticator] {
val itemsPerPage = 9
def remove(id: Long): Action[AnyContent] = SecuredAction.async { implicit request =>
WorkEntry.remove(id)
Future.successful(Redirect(routes.CoinController.landing()))
}
}
示例2: JSONCtrl
//设置package包名称以及导入依赖的类
package controllers.io
import javax.inject.Inject
import com.mohiva.play.silhouette.api.Environment
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import controllers.{ResultFormat, ViewContext}
import models.{PCMAPIUtils, User}
import org.opencompare.api.java.impl.io.KMFJSONExporter
import org.opencompare.formalizer.extractor.CellContentInterpreter
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.MessagesApi
import play.api.libs.json.Json
import play.api.mvc.{AnyContent, Request, Result}
class JSONCtrl @Inject() (
val messagesApi: MessagesApi,
val env: Environment[User, CookieAuthenticator],
val pcmAPIUtils : PCMAPIUtils) extends IOCtrl("json") {
val jsonExporter = new KMFJSONExporter()
val formalizer = new CellContentInterpreter
val outputParametersForm = Form(
mapping(
"file" -> text
)(JSONExportParameters.apply)(JSONExportParameters.unapply)
)
override def importPCMs(format: ResultFormat)(implicit request: Request[AnyContent], viewContext: ViewContext): Result = {
NotFound("JSON import is not implemented yet")
}
override def exportPCM(implicit request: Request[AnyContent]): Result = {
val parameters = outputParametersForm.bindFromRequest.get
val pcmJSON = Json.parse(parameters.pcm)
val container = pcmAPIUtils.parsePCMContainers(pcmJSON).head
formalizer.interpretCells(container.getPcm)
val json = jsonExporter.export(container)
Ok(json)
}
case class JSONExportParameters(pcm : String)
}
示例3: messagesApi
//设置package包名称以及导入依赖的类
package com.github.jacobono.modules
import com.mohiva.play.silhouette.api.Environment
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.services.AvatarService
import com.mohiva.play.silhouette.api.util.Clock
import com.mohiva.play.silhouette.api.util.PasswordHasher
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import com.mohiva.play.silhouette.impl.providers.{ CredentialsProvider, SocialProviderRegistry }
import com.softwaremill.macwire._
import play.api.Configuration
import play.api.i18n.MessagesApi
import com.github.jacobono.controllers._
import com.github.jacobono.models.User
import com.github.jacobono.models.services.UserService
import com.github.jacobono.utils.CSRFHelper
trait ControllerModule {
def messagesApi: MessagesApi
def silhouetteEnvironment: Environment[User, CookieAuthenticator]
def socialProviderRegistry: SocialProviderRegistry
def csrfHelper: CSRFHelper
def userService: UserService
def authInfoRepository: AuthInfoRepository
def credentialsProvider: CredentialsProvider
def configuration: Configuration
def clock: Clock
def avatarService: AvatarService
def passwordHasher: PasswordHasher
lazy val applicationController: Application = wire[Application]
lazy val credentialsAuthController: CredentialsAuthController = wire[CredentialsAuthController]
lazy val signUpController: SignUpController = wire[SignUpController]
lazy val socialAuthController: SocialAuthController = wire[SocialAuthController]
}
示例4: SilhouetteModule
//设置package包名称以及导入依赖的类
package auth.http.module
import auth.core.DefaultEnv
import auth.core.module.SilhouetteContext
import auth.core.service.BasicUserService
import auth.core.service.authorization.PermissionsAuthorizer
import auth.http.service.impl.BasicUserServiceViaHttpImpl
import auth.http.service.impl.authorization.impl.PermissionsViaHttpAuthorizer
import com.google.inject.{AbstractModule, Provides}
import com.mohiva.play.silhouette.api.{Environment, EventBus}
import com.mohiva.play.silhouette.api.services.AuthenticatorService
import net.codingwell.scalaguice.ScalaModule
import play.api.Configuration
import play.api.libs.ws.WSClient
import scala.concurrent.ExecutionContext
sealed class SilhouetteModule extends AbstractModule with ScalaModule {
override def configure(): Unit = {}
@Provides
def providePermissionsAuthorizer(configuration: Configuration, ws: WSClient)(
implicit ec: ExecutionContext): PermissionsAuthorizer =
new PermissionsViaHttpAuthorizer(configuration, ws)(ec)
@Provides
def provideUserService(configuration: Configuration,
wsClient: WSClient,
@SilhouetteContext ec: ExecutionContext): BasicUserService =
new BasicUserServiceViaHttpImpl(configuration, wsClient)(ec)
@Provides
def provideEnvironment(userService: BasicUserService,
eventBus: EventBus,
authenticatorService: AuthenticatorService[DefaultEnv#A],
@SilhouetteContext ec: ExecutionContext): Environment[DefaultEnv] =
Environment[DefaultEnv](userService, authenticatorService, Seq(), eventBus)(ec)
}
示例5: Statistics
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import com.mohiva.play.silhouette.api.{Environment, Silhouette}
import com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticator
import models._
import models.daos._
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent}
import scala.collection.immutable.ListMap
import scala.concurrent.ExecutionContext.Implicits._
class Statistics @Inject()(statisticsDAO: StatisticsDAO,
organisationDAO: OrganisationDAO,
val messagesApi: MessagesApi,
val env: Environment[User, SessionAuthenticator])
extends Silhouette[User, SessionAuthenticator] {
def statistics: Action[AnyContent] = SecuredAction.async { implicit request =>
for {
friday <- statisticsDAO.friday
saturday <- statisticsDAO.saturday
sorting <- statisticsDAO.sorting
selling <- statisticsDAO.selling
organisations <- organisationDAO.all
} yield {
val statistics = ListMap(
Messages("friday") -> fill(organisations, friday),
Messages("saturday") -> fill(organisations, saturday),
Messages("sorting") -> fill(organisations, sorting),
Messages("selling") -> fill(organisations, selling)
)
Ok(views.html.statistics(statistics, request.identity))
}
}
private def fill(organisations: Seq[Organisation], statistic: Map[String, Int]): Map[String, Int] =
organisations.map(organisation => (organisation.name, statistic.getOrElse(organisation.name, 0))).toMap
def friday: Action[AnyContent] = SecuredAction.async { implicit request =>
statisticsDAO.friday.map(statistics => Ok(Json.toJson(statistics)))
}
def saturday: Action[AnyContent] = SecuredAction.async { implicit request =>
statisticsDAO.saturday.map(statistics => Ok(Json.toJson(statistics)))
}
def sorting: Action[AnyContent] = SecuredAction.async { implicit request =>
statisticsDAO.sorting.map(statistics => Ok(Json.toJson(statistics)))
}
def selling: Action[AnyContent] = SecuredAction.async { implicit request =>
statisticsDAO.selling.map(statistics => Ok(Json.toJson(statistics)))
}
}
示例6: Application
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import com.mohiva.play.silhouette.api.{Environment, LogoutEvent, Silhouette}
import com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticator
import forms._
import models.User
import play.api.i18n.MessagesApi
import scala.concurrent.Future
class Application @Inject()(val messagesApi: MessagesApi, val env: Environment[User, SessionAuthenticator])
extends Silhouette[User, SessionAuthenticator] {
def index = UserAwareAction { implicit request =>
Ok(views.html.index(request.identity))
}
def dashboard = SecuredAction { implicit request =>
Ok(views.html.dashboard(request.identity))
}
def signIn = UserAwareAction.async { implicit request =>
request.identity match {
case Some(_) => Future.successful(Redirect(routes.Application.index()))
case None => Future.successful(Ok(views.html.signIn(SignInForm.form)))
}
}
def signUp = SecuredAction { implicit request =>
Ok(views.html.signUp(SignUpForm.form))
}
def signOut = SecuredAction.async { implicit request =>
val result = Redirect(routes.Application.index())
env.eventBus.publish(LogoutEvent(request.identity, request, request2Messages))
env.authenticatorService.discard(request.authenticator, result)
}
}
示例7: Persons
//设置package包名称以及导入依赖的类
package controllers
import java.util.UUID
import javax.inject.Inject
import com.mohiva.play.silhouette.api.{Environment, Silhouette}
import com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticator
import models.User
import models.daos._
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.json._
import scala.concurrent.ExecutionContext.Implicits._
import scala.concurrent.Future
class Persons @Inject()(personDAO: PersonDAO,
val messagesApi: MessagesApi,
val env: Environment[User, SessionAuthenticator])
extends Silhouette[User, SessionAuthenticator] {
def all = SecuredAction.async {
personDAO.all.map(persons => Ok(Json.toJson(persons)))
}
def get(id: String) = SecuredAction.async {
try {
personDAO.get(UUID.fromString(id)).map {
case Some(person) => Ok(Json.toJson(person))
case None => NotFound(Json.toJson(Messages("person.not_found")))
}
} catch {
case _: IllegalArgumentException => Future.successful(BadRequest(Json.toJson(Messages("uuid.invalid"))))
}
}
}
示例8: CrewController
//设置package包名称以及导入依赖的类
package controllers.api
import java.util.UUID
import com.google.inject.Inject
import com.mohiva.play.silhouette.api.Environment
import com.mohiva.play.silhouette.impl.authenticators.JWTAuthenticator
import com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry
import dao.RepoFor
import models.tenant.persistable.PersistableCrew
import models.tenant.{Crew, AuthCrewUser}
import play.api._
import play.api.db.slick.DatabaseConfigProvider
import play.api.i18n.MessagesApi
import play.api.libs.json.{Writes, Reads}
import play.api.mvc._
class CrewController @Inject()(dbConfigProvider: DatabaseConfigProvider,
messagesApi: MessagesApi,
env: Environment[AuthCrewUser, JWTAuthenticator],
socialProviderRegistry: SocialProviderRegistry)
extends GenericSecureApiController(dbConfigProvider, messagesApi, env, socialProviderRegistry)
{
override type Id = UUID
override type Model = Crew
override type PersistedModel = PersistableCrew
override def convertToPersistable = PersistableCrew.build
override def convertToDisplayable = _.convert
override val repo: RepoFor[PersistedModel, Id] = dao.tenant.CrewRepo
override implicit val reads: Reads[Model] = models.tenant.json.CrewJson.crewReads
override implicit val writes: Writes[Model] = models.tenant.json.CrewJson.crewWrites
}