import models.User import play.api._ import play.api.mvc._ import net.liftweb.json._ import net.liftweb.json.JsonDSL import net.liftweb.json.Serialization.write import
scala.collection.mutable.ListBuffer
object Application extends Controller {implicit val format = DefaultFormats def index = Action {Ok(views.html.index())} def newUserSign = Action {Ok(views.html.newUserSignUpForm())} def newUserSignUP = Action {implicit request = > val a = request.body.asFormUrlEncoded val id = a.get( "id")。head val fnm = a.get( "fnm")。head val lnm = a.get( "lnm")。head val email = a.get( "email")。head val res = a.get( "res")。head val num = a.get( "num")。head val pwd = a.get( "pwd")。head
val obj = User(id, fnm, lnm, email, res, num, pwd);
if (models.UserModel.create(obj) > 0) {
Ok(views.html.newUserWlcmPage())
} else {
Ok(views.html.Error())
}
//Ok(" congratulation u r finally registered.. your id is " + id + " & your name is => " + fnm + " And you lives in ::" + res) } def newUserSignUP1 = Action {
Ok(views.html.newUserWlcmPage()) }
def signIn = Action { implicit request =>
val a = request.body.asFormUrlEncoded
val id = a.get("id").head
val pwd = a.get("pwd").head
val data = models.UserModel.userDetail(id, pwd)
Redirect(routes.Application.shwUserDetail).withSession( "id"-> id)
// Ok(views.html.userInfoPage(data))。withSession( "id"-> id)}
def signInUser = Action {Ok(views.html.login())} def shwUserDetail = Action {implicit request => val id = request.session.get( "id")。get val usrDetail = models.UserModel.userDetail(id )Ok(views.html.userInfoPage(usrDetail))} def userDetail = Action {implicit request => val b = request.body.asFormUrlEncoded if(!session.get( "id")。isEmpty){val id=session。 get( "id")。get // val password = b.get( "pwd")。head
val data = models.UserModel.getAllUserDetail(id)
Ok(write(data))
} else {
Ok("")
} } def sendRequest = Action { implicit request =>
val b = request.body.asFormUrlEncoded.get
val receiver_id = b.get("receiver_id").get(0)
val sender_id = request.session.get("id").get
val data = models.UserModel.friendRequest(sender_id, receiver_id)
Ok(write(Map("sucess"->true))) } def logout() = Action {
println("You are successfully logout")
Ok(views.html.logout()).withNewSession } def friendList = Action { implicit request => val b = request.body.asFormUrlEncoded
val sender_id = request.session.get( "id")。get val data = models.UserModel.friendList(sender_id)
Ok(views.html.requestConfirmation())
} def requestList = Action {implicit request => val sender_id = request.session.get( "id")。get val data = models.UserModel.requestList(sender_id)Ok(write(data))
}
def acceptRequest = Action { implicit request =>
val b = request.body.asFormUrlEncoded.get
val friend_id = b.get("friend_id").get(0)
val user_id = request.session.get("id").get
val data = models.UserModel.acceptRequest(friend_id, user_id)
Ok(write(Map("sucess"->true))) } }
そして、ほくろは
パッケージモデルimportplay.api.db._import play.api.Play.current
import anorm._ import anorm.SqlParser._
case class User(id:String、fnm:String、lnm:String、email:String、res:String、num:String、pwd:String)case class User1(sender_id:String、receiver_id:String)object UserModel {
def create(obj:User)= {
DB.withConnection { implicit Connection =>
val data = SQL("insert into user_detail values({id},{fnm},{lnm},{email},{res},{num},{pwd})").on("id" ->
obj.id、 "fnm"-> obj.fnm、 "lnm"-> obj.lnm、 "email"-> obj.email、 "res"-> obj.res、 "num"-> obj.num、 " pwd "-> obj.pwd).executeUpdate()
data
} } def userDetail(id: String, pwd: String): List[User] = {
DB.withConnection { implicit Connection =>
val dat = SQL("select * from user_detail where id='" + id + "' and pwd='" + pwd +"'")
var data = dat().map(row =>
User(row[String]("id"),row[String]("fnm"), row[String]("lnm"), row[String]("email"),row[String]("res"),row[String]("num"),row[String]("pwd"))).toList
data
} } def userDetail(id: String): List[User] = {
DB.withConnection { implicit Connection =>
val dat = SQL("select * from user_detail where id='" + id + "'")
var data = dat().map(row =>
User(row[String]("id"),row[String]("fnm"), row[String]("lnm"), row[String]("email"),row[String]("res"),row[String]("num"),row[String]("pwd"))).toList
data
} } def friendRequest(sender_id:String,receiver_id:String)={
DB.withConnection{ implicit c=>
val result=SQL("insert into request_table values ({sender_id},{receiver_id})").on("sender_id"->sender_id,"receiver_id"->receiver_id).executeInsert()
println("------------------------------------\n"+result);
result
}
} def getAllUserDetail(id: String) = {
DB.withConnection { implicit Connection =>
val dat = SQL("select * from user_detail where id!='" + id +"'")
var data = dat().map(row =>
User(row[String]("id"),row[String]("fnm"), row[String]("lnm"), row[String]("email"),row[String]("res"),row[String]("num"),row[String]("pwd"))).toList
data
} }
def friendList(user_id: String) = {
DB.withConnection { implicit Connection =>
val dat = SQL("select * from friend_tbl where id!='" + user_id +"'")
var data = dat().map(row =>
User(row[String]("id"),row[String]("fnm"), row[String]("lnm"), row[String]("email"),row[String]("res"),row[String]("num"),row[String]("pwd"))).toList
data
} } def requestList(sender_id: String) = {
DB.withConnection { implicit Connection =>
val dat = SQL("select receiver_id from request_table where sender_id='" + sender_id +"'")
var data = dat().map(row =>
row[String]("receiver_id")).toList
data
} } def acceptRequest(friend_id:String, user_id:String)={
DB.withConnection{ implicit c=
ブロッククォート
val result=SQL("insert into friend_tbl values ({friend_id},{user_id})").on("friend_id"->friend_id,"user_id"->user_id).executeInsert()
println("------------------------------------\n"+result);
result
}
} }
その後、表示ページを構成しますenter code here
静的リソースを/publicフォルダーから/assetsURLパスにマップします。GET/assets/ * file controllers.Assets.at(path = "/ public"、file)