public override async Task GrantResourceOwnerCredentials (OAuthGrantResourceOwnerCredentialsContext context) { using (var obj = new WgsnEntities()) { user_master entry = obj.user_master.Where <user_master>(record => record.user_name == context.UserName && record.user_password == context.Password).FirstOrDefault(); if (entry == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } } ClaimsIdentity oAuthIdentity = new ClaimsIdentity(context.Options.AuthenticationType); ClaimsIdentity cookiesIdentity = new ClaimsIdentity(context.Options.AuthenticationType); AuthenticationProperties properties = CreateProperties(context.UserName); AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties); context.Validated(ticket); context.Request.Context.Authentication.SignIn(cookiesIdentity); }
// GET: Account public ActionResult Index(user_master _user) { if (_user.email == null && _user.password == null) { return(View()); } var user = dc.user_master.Where(u => u.email == _user.email && u.password == _user.password).FirstOrDefault(); if (user != null) { Response.Cookies["IChat_user"].Value = user.name; string returnUrl = "~/Home/Index"; if (Request.QueryString["returnUrl"] != null) { returnUrl = Request.QueryString["returnUrl"]; } return(RedirectToAction("Index", "Home", new { id = user.id })); //return Redirect(returnUrl); } else { ViewBag.message = "帳號密碼錯誤請重新輸入!!"; return(View()); } }
public ActionResult DeleteConfirmed(int id) { user_master user_master = db.user_master.Find(id); db.user_master.Remove(user_master); db.SaveChanges(); return(RedirectToAction("Index")); }
protected void Button1_Click(object sender, EventArgs e) { int flag = 0; DataClasses2DataContext dcd = new DataClasses2DataContext(); var query = from t1 in dcd.user_masters where t1.username == TextBox1.Text select t1; if (query.Count() > 0) { flag = 1; Label1.Text = "Username is already in use"; } var query1 = from t1 in dcd.user_masters where t1.email == TextBox4.Text select t1; if (query1.Count() > 0) { flag = 1; Label2.Text = "Email address is already in use"; } if (flag == 0) { user_master us = new user_master(); us.username = TextBox1.Text; us.password = Crypto.Hash(TextBox2.Text); us.email = TextBox4.Text; us.sequrity_que = DropDownList1.SelectedItem.Text; us.sequrity_ans = TextBox5.Text; us.role_name = "user"; dcd.user_masters.InsertOnSubmit(us); try { dcd.SubmitChanges(); //Random rndm = new Random(); MailMessage message = new MailMessage(); message.From = new MailAddress("*****@*****.**"); message.To.Add(new MailAddress(TextBox4.Text)); message.Subject = "Welcome to ExamCenter"; message.Body = "Your account created successfully.Test your self with different tests and improve your preparation for exams"; message.IsBodyHtml = true; SmtpClient client = new SmtpClient(); client.Host = "smtp.gmail.com"; client.Port = 587;//Gmail port number client.UseDefaultCredentials = true; client.EnableSsl = true; client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "nikhilkrishna"); client.Send(message); ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Account created successfully!!login here');window.location ='login.aspx';", true); } catch (Exception ee) { ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('try again!');window.location ='createaccount.aspx';", true); } } }
public ActionResult Signup(user_master model) { using (var context = new ProductManagementEntities()) { context.user_master.Add(model); context.SaveChanges(); } return(RedirectToAction("Login")); }
public Response AdUsers([FromBody] user_master user) { using (WgsnEntities db = new WgsnEntities()) { //db.user_master.Add(user); //db.SaveChanges(); } return(new Response(true, "Success", user)); }
public ActionResult Edit([Bind(Include = "Id,Name,EmailID,Password")] user_master user_master) { if (ModelState.IsValid) { db.Entry(user_master).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user_master)); }
public ActionResult Create([Bind(Include = "Id,Name,EmailID,Password")] user_master user_master) { if (ModelState.IsValid) { db.user_master.Add(user_master); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user_master)); }
public ActionResult Add(user_master user) { user_master _user = new user_master(); _user.name = user.name; _user.phone = user.phone; _user.email = user.email; repository.Create(_user); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "user_id,u_first_name,u_last_name,c_id,role_id,UserName,phone_no,email_id,Password")] user_master user_master) { if (ModelState.IsValid) { db.Entry(user_master).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.c_id = new SelectList(db.company_master, "c_id", "c_name", user_master.c_id); ViewBag.role_id = new SelectList(db.role_master, "role_id", "roll_name", user_master.role_id); return(View(user_master)); }
// GET: UserManagement/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } user_master user_master = db.user_master.Find(id); if (user_master == null) { return(HttpNotFound()); } return(View(user_master)); }
public ActionResult Login(user_master model) { using (var context = new ProductManagementEntities()) { bool isValid = context.user_master.Any(x => x.EmailID == model.EmailID && x.Password == model.Password); if (isValid) { FormsAuthentication.SetAuthCookie(model.EmailID, false); return(RedirectToAction("Index", "DataConnect")); } ModelState.AddModelError("", "Invalid emailid and password"); return(View()); } }
// GET: UserManagement/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } user_master user_master = db.user_master.Find(id); if (user_master == null) { return(HttpNotFound()); } ViewBag.c_id = new SelectList(db.company_master, "c_id", "c_name", user_master.c_id); ViewBag.role_id = new SelectList(db.role_master, "role_id", "roll_name", user_master.role_id); return(View(user_master)); }
public ActionResult Edit(user_master user) { //接收表單傳過來的資料 user_master _user = new user_master(); _user.id = user.id; _user.name = user.name; _user.phone = user.phone; _user.email = user.email; //將資料傳給Model修改 repository.Update(_user); //轉到Index Action顯示修改完的結果 return(RedirectToAction("Index")); }
protected void Button1_Click(object sender, EventArgs e) { int flag = 0; DataClasses2DataContext dcd = new DataClasses2DataContext(); var query = from t1 in dcd.user_masters where t1.username == TextBox1.Text select t1; if (query.Count() > 0) { flag = 1; Label1.Text = "Username is already in use"; } var query1 = from t1 in dcd.user_masters where t1.email == TextBox4.Text select t1; if (query1.Count() > 0) { flag = 1; Label2.Text = "Email address is already in use"; } if (flag == 0) { user_master us = new user_master(); us.username = TextBox1.Text; us.password = Crypto.Hash(TextBox2.Text); us.email = TextBox4.Text; us.sequrity_que = DropDownList1.SelectedItem.Text; us.sequrity_ans = TextBox5.Text; us.role_name = "admin"; dcd.user_masters.InsertOnSubmit(us); try { dcd.SubmitChanges(); ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Account created successfully!!login here');window.location ='login.aspx';", true); } catch (Exception ee) { ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('try again');window.location ='signupadmin.aspx';", true); } } }
public async Task <ActionResult> Login(user_master model, string returnUrl) { if (ModelState.IsValid) { DataTable dt = new DataTable(); var a = db.user_master.ToList(); int userExists = db.user_master.Where(x => x.UserName == model.UserName && x.Password == model.Password).Count(); if (userExists == 1) { return(RedirectToAction("Index", "AdminDashboard")); } else { ModelState.AddModelError("CustomError", "Invalid username or password."); } } else { return(View(model)); } return(View(model)); //if (ModelState.IsValid) //{ // var user = await UserManager.FindAsync(model.UserName, model.Password); // if (user != null) // { // await SignInAsync(user, model.RememberMe); // return RedirectToLocal(returnUrl); // } // else // { // ModelState.AddModelError("", "Invalid username or password."); // } //} //// If we got this far, something failed, redisplay form //return View(model); }
protected void Button1_Click(object sender, EventArgs e) { DataClasses2DataContext cd = new DataClasses2DataContext(); if (MultiView1.ActiveViewIndex == 0) { var query = from t1 in cd.user_masters where t1.username == TextBox1.Text select t1; if (query.Count() == 0) { Label1.Text = "Enter valid username"; } else { var query1 = from t1 in cd.user_masters where t1.username == TextBox1.Text select t1; foreach (var i in query1) { Label6.Text = i.sequrity_que; } MultiView1.ActiveViewIndex = 1; } } else if (MultiView1.ActiveViewIndex == 1) { var query1 = from t1 in cd.user_masters where t1.username == TextBox1.Text select t1; if (TextBox5.Text == null) { Label2.Text = "enter answer"; } else { foreach (var i in query1) { if (TextBox5.Text == i.sequrity_ans) { MultiView1.ActiveViewIndex = 2; } if (TextBox5.Text != i.sequrity_ans && TextBox5.Text != "") { TextBox5.Text = ""; Label2.Text = "enter right answer again"; } } } } else if (MultiView1.ActiveViewIndex == 2) { user_master us = new user_master(); if (TextBox3.Text == TextBox4.Text && TextBox3.Text != "" && TextBox4.Text != "") { flag = 1; var qu = from t1 in cd.user_masters where t1.username == TextBox1.Text select t1; foreach (var i in qu) { i.password = Crypto.Hash(TextBox4.Text); cd.SubmitChanges(); } } if (flag == 1) { ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Password chnaged successfully!please login again');window.location ='login.aspx';", true); } } }