Skip to content

Instantly share code, notes, and snippets.

@FernandoZhuang
Last active April 29, 2018 03:42
Show Gist options
  • Save FernandoZhuang/759488189af25a8191de8064bc64cbe2 to your computer and use it in GitHub Desktop.
Save FernandoZhuang/759488189af25a8191de8064bc64cbe2 to your computer and use it in GitHub Desktop.
Webchat:Register
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