当前位置: 首页>>代码示例>>Scala>>正文


Scala UserDAO类代码示例

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


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

示例1: save

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

import java.util.UUID

import javax.inject.Inject
import com.mohiva.play.silhouette.api.LoginInfo
import models.User
import models.daos.UserDAO
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global


  def save(user: User): Future[User] = user match {
    case User(id, _, _, _, _, _) =>
      find(id).map { u =>
        u match {
          case Some(origUser) =>
            UserDAOImpl.users = UserDAOImpl.users.filterNot(_ == origUser) + user; user

          case None =>
            UserDAOImpl.users = UserDAOImpl.users + user; user
        }
      }
  }
}

object UserDAOImpl {
  var users = Set[User]( //User(UUID.randomUUID, LoginInfo("credentials", ))
  )
} 
开发者ID:yoo-haemin,项目名称:hufs-planner,代码行数:31,代码来源:UserDAOImpl.scala

示例2: Authentication

//设置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.util.Credentials
import com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticator
import com.mohiva.play.silhouette.impl.exceptions.IdentityNotFoundException
import com.mohiva.play.silhouette.impl.providers._
import forms.SignInForm
import models.User
import models.daos.UserDAO
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc.Action

import scala.concurrent.Future

class Authentication @Inject()(val messagesApi: MessagesApi,
                               val env: Environment[User, SessionAuthenticator],
                               userDAO: UserDAO,
                               credentialsProvider: CredentialsProvider)
  extends Silhouette[User, SessionAuthenticator] {

  def authenticate = Action.async { implicit request =>
    SignInForm.form.bindFromRequest.fold(
      form => Future.successful(BadRequest(views.html.signIn(form))),
      data => {
        val credentials = Credentials(data.email, data.password)
        credentialsProvider.authenticate(credentials).flatMap { loginInfo =>
          val result = Redirect(routes.Application.dashboard())
          userDAO.retrieve(loginInfo).flatMap {
            case Some(user) =>
              env.authenticatorService.create(loginInfo).flatMap { authenticator =>
                env.eventBus.publish(LoginEvent(user, request, request2Messages))
                env.authenticatorService.init(authenticator).flatMap { v =>
                  env.authenticatorService.embed(v, result)
                }
              }
            case None => Future.failed(new IdentityNotFoundException(Messages("user.not_found")))
          }
        }.recover {
          case _: ProviderException =>
            Redirect(routes.Application.signIn()).flashing("error" -> Messages("invalid.credentials"))
        }
      }
    )
  }
} 
开发者ID:wjglerum,项目名称:bamboesmanager,代码行数:51,代码来源:Authentication.scala

示例3: SignUp

//设置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.PasswordHasher
import com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticator
import com.mohiva.play.silhouette.impl.providers._
import forms.SignUpForm
import models.User
import models.daos.UserDAO
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc.Action

import scala.concurrent.Future

class SignUp @Inject()(val messagesApi: MessagesApi,
                       val env: Environment[User, SessionAuthenticator],
                       userDAO: UserDAO,
                       authInfoRepository: AuthInfoRepository,
                       passwordHasher: PasswordHasher)
  extends Silhouette[User, SessionAuthenticator] {

  def signUp = Action.async { implicit request =>
    SignUpForm.form.bindFromRequest.fold(
      form => Future.successful(BadRequest(views.html.signUp(form))),
      data => {
        val loginInfo = LoginInfo(CredentialsProvider.ID, data.email)
        userDAO.retrieve(loginInfo).flatMap {
          case Some(_) =>
            Future.successful(Redirect(routes.Application.signUp()).flashing("error" -> Messages("user.exists")))
          case None =>
            val authInfo = passwordHasher.hash(data.password)
            val user = User(
              id = UUID.randomUUID(),
              name = data.name,
              email = data.email
            )
            for {
              user <- userDAO.save(user)
              _ <- authInfoRepository.add(loginInfo, authInfo)
              authenticator <- env.authenticatorService.create(loginInfo)
              value <- env.authenticatorService.init(authenticator)
              result <- env.authenticatorService.embed(value, Redirect(routes.Application.dashboard()))
            } yield {
              env.eventBus.publish(SignUpEvent(user, request, request2Messages))
              env.eventBus.publish(LoginEvent(user, request, request2Messages))
              result
            }
        }
      }
    )
  }
} 
开发者ID:wjglerum,项目名称:bamboesmanager,代码行数:58,代码来源:SignUp.scala


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