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

Scala UserDAO类代码示例

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

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala JSONCollection类代码示例发布时间:2022-05-23
下一篇:
Scala JsonDeserialize类代码示例发布时间: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