{
public class UserController : SurfaceController
{
[HttpPost]
public ActionResult UserLogin(SigInModel loginModel)
{
try
{
if (ModelState.IsValid)
{
var memberservice = UmbracoContext.Application.Services.MemberService;
var user = Members.GetByEmail(loginModel.Email);
if (memberservice.Exists(loginModel.Email) && Members.Login(loginModel.Email, loginModel.Password))
{
FormsAuthentication.SetAuthCookie(loginModel.Email, false);
TempData["success"] = "User LogedIn Successfully";
return RedirectToUmbracoPage(Umbraco.TypedContentAtRoot().FirstOrDefault().Id);
}
else
{
TempData["error"] = "Plese Register";
}
}
else
{
TempData["error"] = "There is some issue with model validation";
}
}
catch (Exception exp)
{
TempData["error"] = exp.Message;
}
return CurrentUmbracoPage();
}
[HttpPost]
public ActionResult UserRegister(RegisterationModel registerModel)
{
try
{
if (ModelState.IsValid)
{
var memberservice = UmbracoContext.Application.Services.MemberService;
if (!memberservice.Exists(registerModel.Email))
{
var defMemberType = memberservice.GetDefaultMemberType();
var newMemeber = memberservice.CreateMember(registerModel.Email, registerModel.Email, registerModel.Name, defMemberType);
memberservice.Save(newMemeber);
memberservice.SavePassword(newMemeber, registerModel.Password);
UmbracoContext.Application.Services.MemberService.AssignRole(newMemeber.Id, "Admin");
TempData["success"] = "You are succesfully registered";
}
else
{
TempData["error"] = "User already exists";
}
}
else
{
TempData["error"] = "There is some issue with model validation";
}
}
catch (Exception exp)
{
TempData["error"] = exp.Message;
}
return RedirectToCurrentUmbracoPage();
}
}
}
public class UserController : SurfaceController
{
[HttpPost]
public ActionResult UserLogin(SigInModel loginModel)
{
try
{
if (ModelState.IsValid)
{
var memberservice = UmbracoContext.Application.Services.MemberService;
var user = Members.GetByEmail(loginModel.Email);
if (memberservice.Exists(loginModel.Email) && Members.Login(loginModel.Email, loginModel.Password))
{
FormsAuthentication.SetAuthCookie(loginModel.Email, false);
TempData["success"] = "User LogedIn Successfully";
return RedirectToUmbracoPage(Umbraco.TypedContentAtRoot().FirstOrDefault().Id);
}
else
{
TempData["error"] = "Plese Register";
}
}
else
{
TempData["error"] = "There is some issue with model validation";
}
}
catch (Exception exp)
{
TempData["error"] = exp.Message;
}
return CurrentUmbracoPage();
}
[HttpPost]
public ActionResult UserRegister(RegisterationModel registerModel)
{
try
{
if (ModelState.IsValid)
{
var memberservice = UmbracoContext.Application.Services.MemberService;
if (!memberservice.Exists(registerModel.Email))
{
var defMemberType = memberservice.GetDefaultMemberType();
var newMemeber = memberservice.CreateMember(registerModel.Email, registerModel.Email, registerModel.Name, defMemberType);
memberservice.Save(newMemeber);
memberservice.SavePassword(newMemeber, registerModel.Password);
UmbracoContext.Application.Services.MemberService.AssignRole(newMemeber.Id, "Admin");
TempData["success"] = "You are succesfully registered";
}
else
{
TempData["error"] = "User already exists";
}
}
else
{
TempData["error"] = "There is some issue with model validation";
}
}
catch (Exception exp)
{
TempData["error"] = exp.Message;
}
return RedirectToCurrentUmbracoPage();
}
}
}
No comments:
Post a Comment