public async Task <ActionResult> Login(Utilizatori usr) { using (var db = new BLCEntities1()) { Utilizatori usrExists = db.Utilizatori.Where(u => (u.Email == usr.Email && u.Parola == usr.Parola)).FirstOrDefault(); if (usrExists != null) { Session["Email"] = usrExists.Email; Session["UserId"] = usrExists.UserId; ViewBag.Email = usrExists.Email; ViewBag.UserId = usrExists.UserId; return(RedirectToAction("Index", "Home")); } else { ViewBag.ErrMsg = "Login failed"; Session["Email"] = null; Session["UserId"] = null; ViewBag.Email = string.Empty; ViewBag.UserId = "-1"; } } return(View()); }
public async Task <ActionResult> Register(Utilizatori ut) { //if (ModelState.IsValid) //{ // var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; // var result = await UserManager.CreateAsync(user, model.Password); // if (result.Succeeded) // { // await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // // Send an email with this link // // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); // return RedirectToAction("Index", "Home"); // } // AddErrors(result); //} using (var db = new BLCEntities1()) { ViewBag.ErrMsg = string.Empty; ViewBag.SuccessMsg = string.Empty; Utilizatori usr = db.Utilizatori.Where(u => u.Email == ut.Email).FirstOrDefault(); if (usr != null) { ViewBag.ErrMsg = "Adresa de email este deja utilizata"; } else { db.Utilizatori.Add(ut); db.SaveChanges(); ViewBag.SuccessMsg = "Utilizatorul a fost adaugat cu sucess"; } } // If we got this far, something failed, redisplay form return(View()); }