示例#1
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    UserRepository userRep = new UserRepository();

                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        userRep.GetUserID(model.UserName);
                        userRep.GetClientId(model.UserName);
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        userRep.GetUserID(model.UserName);
                        userRep.GetClientId(model.UserName);
                        return RedirectToAction("Home", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
示例#2
0
 public string GetUsername(Guid UserId)
 {
     UserRepository urep = new UserRepository();
     return urep.GetUsername(UserId);
 }
示例#3
0
        public ActionResult Register(RegisterModel model)
        {
            // model.roleName = "School";
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    //FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    Roles.AddUserToRole(model.UserName, model.roleName.ToString());
                    MembershipUser user = Membership.GetUser(model.UserName);
                    Guid guid = (Guid)user.ProviderUserKey;
                    if (model.FirstName == null) { model.FirstName = ""; }
                    if (model.Surname == null) { model.Surname = ""; }

                    //...Add School Details...
                    UserRepository userRep = new UserRepository();
                    userRep.InsertUserSchool(guid, model.ClientId);

                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                    return View(model);
                }
            }

            // If we got this far, something failed, redisplay form
            ViewBag.PasswordLength = MembershipService.MinPasswordLength;
            SelectList sl = new SelectList(Roles.GetAllRoles(), "roleNames");
            //remove items as needed
            ViewData["roleNames"] = sl;
            return View(model);
        }