Last active
April 29, 2018 03:42
-
-
Save FernandoZhuang/759488189af25a8191de8064bc64cbe2 to your computer and use it in GitHub Desktop.
Webchat:Register
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ActionResult Register(){ | |
string user_name = Request.Form["regname"]; | |
string user_pwd = Request.Form["regpass"]; | |
string user_repwd = Request.Form["reregpass"]; | |
if (user_name.Trim() == "" || user_pwd.Trim() == "") | |
{ | |
return Redirect("/"); | |
} | |
if(user_pwd != user_repwd) | |
{ | |
return Redirect("/"); | |
} | |
using (var db = new Models.ChatContext()) | |
{ | |
User user = db.Users.FirstOrDefault(u => u.name == user_name); | |
if (user == null) | |
{ | |
user = new User { name = user_name, pwd = user_pwd, created_at = DateTime.Now }; | |
db.Users.Add(user); | |
db.SaveChanges(); | |
} | |
else | |
{ | |
return Redirect("/"); | |
} | |
Session["user"] = user; | |
} | |
return Redirect("/chat"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment