• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala UserService类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中models.services.UserService的典型用法代码示例。如果您正苦于以下问题:Scala UserService类的具体用法?Scala UserService怎么用?Scala UserService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了UserService类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: ChangePasswordController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.Inject

import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.api.exceptions.ProviderException
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.util.{ Credentials, PasswordHasherRegistry, PasswordInfo }
import com.mohiva.play.silhouette.impl.providers.CredentialsProvider
import models.services.UserService
import play.api.i18n.{ I18nSupport, Messages, MessagesApi }
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc.Controller
import utils.auth.{ DefaultEnv, WithProvider }

import scala.concurrent.Future

class ChangePasswordController @Inject() (
  val messagesApi: MessagesApi,
  silhouette: Silhouette[DefaultEnv],
  userService: UserService,
  credentialsProvider: CredentialsProvider,
  authInfoRepository: AuthInfoRepository,
  passwordHasherRegistry: PasswordHasherRegistry
)
  extends Controller with I18nSupport {

  def view = silhouette.SecuredAction(WithProvider[DefaultEnv#A](CredentialsProvider.ID)) { implicit request =>
    Ok(views.html.changePassword(new myform.MyChangePasswordForm(), request.identity))
  }

  def submit = silhouette.SecuredAction(WithProvider[DefaultEnv#A](CredentialsProvider.ID)).async { implicit request =>
    new myform.MyChangePasswordForm().bindFromRequest match {
      case form: myform.MyChangePasswordForm => Future.successful(BadRequest(views.html.changePassword(form, request.identity)))
      case data: myform.MyChangePasswordFormData => {
        val (currentPassword, newPassword) = (data.currentPassword, data.newPassword)
        val credentials = Credentials(request.identity.email.getOrElse(""), currentPassword)
        credentialsProvider.authenticate(credentials).flatMap { loginInfo =>
          val passwordInfo = passwordHasherRegistry.current.hash(newPassword)
          authInfoRepository.update[PasswordInfo](loginInfo, passwordInfo).map { _ =>
            Redirect(routes.ChangePasswordController.view()).flashing("success" -> Messages("password.changed"))
          }
        }.recover {
          case e: ProviderException =>
            Redirect(routes.ChangePasswordController.view()).flashing("error" -> Messages("current.password.invalid"))
        }
      }
    }
  }
} 
开发者ID:serversideapps,项目名称:silhmojs,代码行数:51,代码来源:ChangePasswordController.scala


示例2: ResetPasswordController

//设置package包名称以及导入依赖的类
package controllers

import java.util.UUID
import javax.inject.Inject

import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.util.{ PasswordHasherRegistry, PasswordInfo }
import com.mohiva.play.silhouette.impl.providers.CredentialsProvider
import models.services.{ AuthTokenService, UserService }
import play.api.i18n.{ I18nSupport, Messages, MessagesApi }
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc.Controller
import utils.auth.DefaultEnv

import scala.concurrent.Future

class ResetPasswordController @Inject() (
  val messagesApi: MessagesApi,
  silhouette: Silhouette[DefaultEnv],
  userService: UserService,
  authInfoRepository: AuthInfoRepository,
  passwordHasherRegistry: PasswordHasherRegistry,
  authTokenService: AuthTokenService
)
  extends Controller with I18nSupport {

  def view(token: UUID) = silhouette.UnsecuredAction.async { implicit request =>
    authTokenService.validate(token).map {
      case Some(authToken) => Ok(views.html.resetPassword(new myform.MyResetPasswordForm(), token))
      case None => Redirect(routes.SignInController.view()).flashing("error" -> Messages("invalid.reset.link"))
    }
  }

  def submit(token: UUID) = silhouette.UnsecuredAction.async { implicit request =>
    authTokenService.validate(token).flatMap {
      case Some(authToken) =>
        new myform.MyResetPasswordForm().bindFromRequest match {
          case form: myform.MyResetPasswordForm => Future.successful(BadRequest(views.html.resetPassword(form, token)))
          case data: myform.MyResetPasswordFormData => userService.retrieve(authToken.userID).flatMap {
            case Some(user) if user.loginInfo.providerID == CredentialsProvider.ID =>
              val passwordInfo = passwordHasherRegistry.current.hash(data.password)
              authInfoRepository.update[PasswordInfo](user.loginInfo, passwordInfo).map { _ =>
                Redirect(routes.SignInController.view()).flashing("success" -> Messages("password.reset"))
              }
            case _ => Future.successful(Redirect(routes.SignInController.view()).flashing("error" -> Messages("invalid.reset.link")))
          }
        }
      case None => Future.successful(Redirect(routes.SignInController.view()).flashing("error" -> Messages("invalid.reset.link")))
    }
  }
} 
开发者ID:serversideapps,项目名称:silhmojs,代码行数:53,代码来源:ResetPasswordController.scala


示例3: ForgotPasswordController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.Inject

import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.impl.providers.CredentialsProvider
import models.services.{ AuthTokenService, UserService }
import models.daos._
import play.api.i18n.{ I18nSupport, Messages, MessagesApi }
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.mailer.{ Email, MailerClient }
import play.api.mvc.Controller
import utils.auth.DefaultEnv

import scala.concurrent.Future

class ForgotPasswordController @Inject() (
  val messagesApi: MessagesApi,
  silhouette: Silhouette[DefaultEnv],
  userService: UserService,
  authTokenService: AuthTokenService,
  mailerClient: MailerClient,
  envDAO: EnvDAO
)
  extends Controller with I18nSupport {

  def view = silhouette.UnsecuredAction.async { implicit request =>
    Future.successful(Ok(views.html.forgotPassword(new myform.MyForgotPasswordForm())))
  }

  def submit = silhouette.UnsecuredAction.async { implicit request =>
    new myform.MyForgotPasswordForm().bindFromRequest match {
      case form: myform.MyForgotPasswordForm => Future.successful(BadRequest(views.html.forgotPassword(form)))
      case data: myform.MyForgotPasswordFormData => {
        val email = data.email
        val loginInfo = LoginInfo(CredentialsProvider.ID, email)
        val result = Redirect(routes.SignInController.view()).flashing("info" -> Messages("reset.email.sent"))
        userService.retrieve(loginInfo).flatMap {
          case Some(user) if user.email.isDefined =>
            authTokenService.create(user.userID).map { authToken =>
              val url = routes.ResetPasswordController.view(authToken.id).absoluteURL()
              println("url " + url)
              if (envDAO.getDosendmail) mailerClient.send(Email(
                subject = Messages("email.reset.password.subject"),
                from = Messages("email.from"),
                to = Seq(email),
                bodyText = Some(views.txt.emails.resetPassword(user, url).body),
                bodyHtml = Some(views.html.emails.resetPassword(user, url).body)
              ))
              result
            }
          case None => Future.successful(result)
        }
      }
    }
  }
} 
开发者ID:serversideapps,项目名称:silhmojs,代码行数:58,代码来源:ForgotPasswordController.scala


示例4: UserDAOImpl

//设置package包名称以及导入依赖的类
package models.daos


import com.google.inject.Inject
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.exceptions.AuthenticatorCreationException
import models.User
import models.services.UserService
import models.tables.UserTableDef
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.driver.JdbcProfile

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future


class UserDAOImpl @Inject()(protected val dbConfigProvider: DatabaseConfigProvider)
  extends UserDAO with UserService with HasDatabaseConfigProvider[JdbcProfile] {

  import dbConfig.driver.api._

  val users = TableQuery[UserTableDef]

  override def find(id: Long) =
    dbConfig.db.run(users.filter(_.id === id).result.headOption)

  override def find(username: String): Future[Option[User]] =
    dbConfig.db.run(users.filter(_.username === username).result.headOption)

  override def findByEmail(email: String) =
    dbConfig.db.run(users.filter(_.email === email).result.headOption)

  // to implement UserService
  override def retrieve(loginInfo: LoginInfo): Future[Option[User]] = find(loginInfo.providerKey)

  // TODO handle exceptions (-> test)
  override def add(user: User): Future[User] =
    dbConfig.db.run(users returning users += user)
      .recover {
        case e: Exception => throw new AuthenticatorCreationException("failed to create user " + user)
      }

  override def update(user: User) = 
    dbConfig.db.run(users.filter(_.id === user.id).update(user))
      .map {
        case 0 => None
        case _ => Some(user)
      }
} 
开发者ID:agoetschm,项目名称:linkmanager,代码行数:50,代码来源:UserDAOImpl.scala


示例5: LogIn

//设置package包名称以及导入依赖的类
package controllers

import com.google.inject.Inject
import com.mohiva.play.silhouette.api.exceptions.ProviderException
import com.mohiva.play.silhouette.api.{LoginEvent, Silhouette}
import com.mohiva.play.silhouette.api.util.Credentials
import com.mohiva.play.silhouette.impl.exceptions.IdentityNotFoundException
import com.mohiva.play.silhouette.impl.providers.CredentialsProvider
import models.forms.UserLogInForm
import models.services.UserService
import play.api.i18n.{I18nSupport, Messages, MessagesApi}
import play.api.mvc._
import utils.auth.DefaultEnv

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future


class LogIn @Inject()(
                       silhouette: Silhouette[DefaultEnv],
                       userService: UserService,
                       credentialsProvider: CredentialsProvider,
                       val messagesApi: MessagesApi)
  extends Controller with I18nSupport {

  def view = silhouette.UnsecuredAction{ implicit request =>
    Ok(views.html.login(UserLogInForm.form))
  }

  def submit: Action[AnyContent] = silhouette.UnsecuredAction.async { implicit request =>
    UserLogInForm.form.bindFromRequest.fold(
      form => Future.successful(BadRequest(views.html.login(form))),
      data => {
        val credentials = Credentials(data.username, data.password)
        credentialsProvider.authenticate(credentials).flatMap { loginInfo =>
          val result = Redirect(routes.Application.index())
          userService.retrieve(loginInfo).flatMap {
            case Some(user) if !user.activated =>
              Future.successful(Ok(views.html.activateAccount(user.email)))
//              Future.successful(Redirect(routes.LogIn.view()).flashing("error" -> "Account not activated."))
            case Some(user) =>
              silhouette.env.authenticatorService.create(loginInfo).flatMap {
                authenticator =>
                  silhouette.env.eventBus.publish(LoginEvent(user, request))
                  silhouette.env.authenticatorService.init(authenticator).flatMap { v =>
                    silhouette.env.authenticatorService.embed(v, result)
                  }
              }
            case None => Future.failed(new IdentityNotFoundException("Couldn't find user"))
          }
        }
          .recover {
          case e: ProviderException =>
            Redirect(routes.LogIn.view()).flashing("error" -> Messages("invalid.credentials"))
        }
      }
    )
  }

} 
开发者ID:agoetschm,项目名称:linkmanager,代码行数:61,代码来源:LogIn.scala


示例6: messagesApi

//设置package包名称以及导入依赖的类
package controllers

import com.mohiva.play.silhouette.api.actions._
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.services.AvatarService
import com.mohiva.play.silhouette.api.util.{ Clock, PasswordHasher }
import com.mohiva.play.silhouette.impl.providers.{ CredentialsProvider, SocialProviderRegistry }
import com.softwaremill.macwire._
import models.daos.AuthTokenDAOImpl
import models.services.{ AuthTokenServiceImpl, UserService }
import play.api.Configuration
import play.api.i18n.MessagesApi
import utils.auth.{ CustomSecuredErrorHandler, CustomUnsecuredErrorHandler }

trait ControllerModule {
  lazy val authToken = new AuthTokenDAOImpl
  lazy val authTokenService = new AuthTokenServiceImpl(authToken, clock)
  lazy val securedErrorHandler: SecuredErrorHandler = wire[CustomSecuredErrorHandler]
  lazy val unSecuredErrorHandler: UnsecuredErrorHandler = wire[CustomUnsecuredErrorHandler]
  lazy val userAwareAction = new DefaultUserAwareAction(new DefaultUserAwareRequestHandler)
  lazy val securedAction: SecuredAction = new DefaultSecuredAction(new DefaultSecuredRequestHandler(securedErrorHandler))
  lazy val unsecuredAction: UnsecuredAction = new DefaultUnsecuredAction(new DefaultUnsecuredRequestHandler(unSecuredErrorHandler))

  def messagesApi: MessagesApi

  def socialProviderRegistry: SocialProviderRegistry

  def userService: UserService

  def authInfoRepository: AuthInfoRepository

  def credentialsProvider: CredentialsProvider

  def configuration: Configuration

  def clock: Clock

  def avatarService: AvatarService

  def passwordHasher: PasswordHasher

} 
开发者ID:Vinay-bhagwat,项目名称:Silhouette-4.0.0-MacWire,代码行数:43,代码来源:ControllerModule.scala


示例7: DeadboltHandlerImpl

//设置package包名称以及导入依赖的类
package utils.auth.deadbolt

import javax.inject.{ Inject, Singleton }

import be.objectify.deadbolt.scala.models.Subject
import be.objectify.deadbolt.scala.{ AuthenticatedRequest, DeadboltHandler, DynamicResourceHandler }
import com.mohiva.play.silhouette.api.Silhouette
import com.mohiva.play.silhouette.api.util.ExtractableRequest
import models.services.UserService
import play.api.i18n.{ I18nSupport, MessagesApi }
import play.api.mvc.{ Request, Result, Results }
import utils.auth.DefaultEnv

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global


@Singleton
class DeadboltHandlerImpl @Inject() (val messagesApi: MessagesApi, silhouette: Silhouette[DefaultEnv], userService: UserService)
  extends DeadboltHandler with I18nSupport {

  override def beforeAuthCheck[A](request: Request[A]): Future[Option[Result]] = Future.successful(None)

  override def getSubject[A](request: AuthenticatedRequest[A]): Future[Option[Subject]] = {
    implicit val extractableRequest = new ExtractableRequest(request)
    silhouette.env.authenticatorService.retrieve.flatMap {
      case Some(authenticator) =>
        userService.retrieve(authenticator.loginInfo)
      case None => Future.successful(None)
    }
  }

  override def onAuthFailure[A](request: AuthenticatedRequest[A]): Future[Result] = {
    println("Deadbolt: onAuthFailure triggered!")
    Future.successful(Results.Unauthorized) // todo or does this need to accept?
  }

  override def getDynamicResourceHandler[A](request: Request[A]): Future[Option[DynamicResourceHandler]] =
    Future.successful(None)
} 
开发者ID:dexmo007,项目名称:play-sil-seed-exp,代码行数:41,代码来源:DeadboltHandlerImpl.scala


示例8: ProductController

//设置package包名称以及导入依赖的类
package controllers

import scala.concurrent.Future
import javax.inject._

import com.mohiva.play.silhouette.api.Silhouette
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.util.Clock
import com.mohiva.play.silhouette.impl.providers.{CredentialsProvider, SocialProviderRegistry}
import forms.ProductForm
import models.Product
import models.daos.ProductDAO
import models.services.UserService
import play.api.Configuration
import play.api.i18n.I18nSupport
import play.api.i18n.MessagesApi
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc.Controller
import utils.auth.DefaultEnv

@Singleton
class ProductController @Inject()(val messagesApi: MessagesApi,
                                  silhouette: Silhouette[DefaultEnv],
                                  userService: UserService,
                                  authInfoRepository: AuthInfoRepository,
                                  credentialsProvider: CredentialsProvider,
                                  socialProviderRegistry: SocialProviderRegistry,
                                  configuration: Configuration,
                                  clock: Clock,
                                  productDAO: ProductDAO,
                                  implicit val webJarAssets: WebJarAssets)
  extends Controller with I18nSupport {

  private val logger = org.slf4j.LoggerFactory.getLogger(this.getClass)


  def list = silhouette.SecuredAction.async { implicit request =>
    productDAO.all().map { products =>
      logger.info(s"Calling index: products = ${products}")
      Ok(views.html.products.list(request.identity, ProductForm.form, products))
    }
  }

  def add = silhouette.SecuredAction.async { implicit request =>
    ProductForm.form.bindFromRequest.fold(
      form => Future.successful(BadRequest(views.html.products.details(request.identity,ProductForm.form))),
      data => {
        val product = Product(
          ean = data.ean,
          name = data.name,
          description = data.description
        )
        productDAO.insert(product).map(_ => Redirect(routes.ProductController.list))
      }
    )
  }

} 
开发者ID:vahana-team,项目名称:play-slick-silhouette-postgres,代码行数:59,代码来源:ProductController.scala


示例9: Startup

//设置package包名称以及导入依赖的类
package jobs

import java.util.UUID
import javax.inject.Inject
import javax.inject.Singleton

import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.util.PasswordHasherRegistry
import com.mohiva.play.silhouette.impl.providers._
import models.{ User, UserMajor }
import models.MajorType._
import models.services.{ AuthTokenService, UserService, MajorService, UserMajorService }
import utils.auth.DefaultEnv
import shared.Util.reverseEffect

import play.api.libs.concurrent.Execution.Implicits._


@Singleton
class Startup @Inject() (
  silhouette: Silhouette[DefaultEnv],
  userService: UserService,
  majorService: MajorService,
  userMajorService: UserMajorService,
  authInfoRepository: AuthInfoRepository,
  authTokenService: AuthTokenService,
  passwordHasherRegistry: PasswordHasherRegistry) {

  //Create Sample user
  //Major: ??2013, ??2013
  //
  val loginInfo = LoginInfo(CredentialsProvider.ID, "[email protected]")
  val authInfo = passwordHasherRegistry.current.hash("asdf")
  for {
    fmOption <- majorService.find("??????", FirstMajor, 2013)
    smOption <- majorService.find("????????", SecondMajor, 2013)
    userData = User(
      userID = UUID.fromString("42944783-ee3f-4a92-85b9-777c94d9dc5e"),
      loginInfo = loginInfo,
      email = Some("[email protected]"),
      classYear = 2013,
      semester = 5,
      activated = true
    )
    userMajors = Seq(fmOption, smOption).filterNot(_.isEmpty).map(_.get).map(m => UserMajor(userData.userID, m.id))
    savedUserMajors <- reverseEffect(userMajors.map(userMajor => userMajorService.save(userMajor)))
    user <- userService.save(userData)
    authInfo <- authInfoRepository.add(loginInfo, authInfo)
    authToken <- authTokenService.create(user.userID)
  } yield ()
} 
开发者ID:yoo-haemin,项目名称:hufs-planner,代码行数:53,代码来源:Startup.scala


示例10: UserController

//设置package包名称以及导入依赖的类
package controllers

import scala.concurrent.ExecutionContext
import scala.concurrent.Future

import com.mohiva.play.silhouette.api.Silhouette

import javax.inject.Inject
import javax.inject.Singleton
import models.DbModel
import models.Domain
import models.User
import models.services.DomainService
import models.services.UserService
import play.Logger
import play.api.i18n.I18nSupport
import play.api.i18n.MessagesApi
import play.api.mvc.Controller
import viewdata.PaginateData
import utils.auth.DefaultEnv
import controllers.actions.GeneralActions
import controllers.actions.MySecuredRequest
import viewdata._
import models.services.FileService

@Singleton
class UserController @Inject() (
  val messagesApi: MessagesApi,
  val domainService: DomainService,
  val userService: UserService,
  val generalActions: GeneralActions,
  val fileService: FileService,
  implicit val webJarAssets: WebJarAssets)(implicit exec: ExecutionContext)
    extends Controller with I18nSupport {

  def list(page: Int) =
    generalActions.MySecuredAction.async { implicit mySecuredRequest =>
      val responses = for {
        userListData <- userService.getUserList(page, mySecuredRequest.activeDomain.map(activeDomain =>
          activeDomain.allowedUsers).getOrElse(Set()))
      } yield Ok(views.html.users.list(userListData, UserStatus(Some(mySecuredRequest.identity), mySecuredRequest.activeDomain)))

      responses recover {
        case e => InternalServerError(e.getMessage())
      }
    }

  def show(uuid: String, page: Int) =
    (generalActions.MySecuredAction andThen generalActions.UserAction(uuid)).async { implicit userRequest =>
      val responses = for {
        domainListData <- domainService.getDomainList(page, userRequest.user)
        imageExists <- fileService.imageExists(uuid)
      } yield Ok(views.html.users.show(userRequest.user, imageExists, domainListData, 
          UserStatus(Some(userRequest.identity), userRequest.activeDomain)))

      responses recover {
        case e => InternalServerError(e.getMessage())
      }
    }
} 
开发者ID:MagnusAk78,项目名称:mogas,代码行数:61,代码来源:UserController.scala



注:本文中的models.services.UserService类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala ClusterShardingSettings类代码示例发布时间:2022-05-23
下一篇:
Scala BaseEncoding类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap