Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8471635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:50:57+00:00 2026-06-10T16:50:57+00:00

I am having a problem with type mismatch. type mismatch; found : Option[models.User] required:

  • 0

I am having a problem with type mismatch.

type mismatch; found : Option[models.User] required: models.User

def authenticate = Action { implicit request =>
        signinForm.bindFromRequest.fold(
          formWithErrors => BadRequest(html.signin(formWithErrors)),
          user => Redirect(routes.Application.active).withSession(Security.username -> User.getUserName(user))
        )
      }

How can I force the function to accept Option[models.User] or can I convert the models.User into an Option?

The error occurs here: User.getUserName(user). getUserName requires models.User types.

===============================================

Update with all code used:

From User.scala

  def authenticate(email: String, password: String) : Option[User] = {
    (findByEmail(email)).filter { (user => BCrypt.checkpw(password, user.password)) }
  }

  def findByEmail(email: String) : Option[User] = {
    UserDAO.findOne(MongoDBObject("email" -> email))
  }

From Application.scala

  val signinForm = Form {
    mapping(
      "email" -> nonEmptyText, 
      "password" -> text)(User.authenticate)(_.map(user => (user.email, "")))
      .verifying("Invalid email or password", result => result.isDefined)
  }

  def authenticate = Action { implicit request =>
    signinForm.bindFromRequest.fold(
      formWithErrors => BadRequest(html.signin(formWithErrors)),
      user => Redirect(routes.Application.active).withSession(Security.username -> User.getUserName(user.get))
    )
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:50:58+00:00Added an answer on June 10, 2026 at 4:50 pm

    To de-option an Option[User] into a User, you can do one of the following:

    1) The unsafe way. Only do this if you are sure that optUser is not None.

    val optUser: Option[User] = ...
    val user: User = optUser.get
    

    2) The safe way

    val optUser: Option[User] = ...
    optUser match {
      case Some(user) => // do something with user
      case None => // do something to handle the absent user
    }
    

    3) The monadic safe way

    val optUser: Option[User] = ...
    optUser.map(user => doSomething(user))
    

    The biggest thing is that, if it’s possible that optUser might actually be None, you need to figure out what you actually want to happen in the case that there is no User object.

    There’s a lot more information about Option in other StackOverflow questions if you’d like to read more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having a problem with python.. I have a binary tree node type: class
I'm having following problem. I should convert a control to a certain type, this
Having a persistent problem with Jquery in firebug...frequently I'll type some JQuery statement into
I'm having this problem. Shouldn't the constructor have the same type parameters as the
I'm having problem automating to type the text in the textbox with variable id's
I'm having problem with triggering function on delete_post action. I'm building functionality where i
I'm having a problem getting this type conversion working correctly. My guess is the
I am having a problem in type conversion in ARC environment.If anyone would be
i am having a problem in type conversion in ARC environment.if anyone would be
I am having a problem with data type conversion that I just can figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.