Esempio n. 1
0
 private async Task SignInAsync(ApplicationUser user, bool isPersistent)
 {
     //AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
     var identity = await _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
     AuthenticationManager.SignIn( identity);
 }
Esempio n. 2
0
        public async Task<ActionResult> TerminalUsersRegister(RegisterTerminalUserViewModel model, FormCollection formCollection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (
                        !_dbManager.Users.Any(
                            p => p.UserName == model.UserName.ToLower() && p.Email == model.Email.ToLower()))
                    {
                        var user = new ApplicationUser
                        {
                            UserName = model.UserName.ToLower(),
                            LastLogin = DateTime.Now,
                            Deactivated = false,
                            Enabled = false,
                            Email = model.Email.ToLower(),
                            FirstName = model.Firstname,
                            LastName = model.Lastname,
                            PhoneNumber = model.PhoneNumber,
                            AlternateNumber = model.AlternateNumber,
                            IdentificationNumber = model.IdentificationNumber,
                            OsysDateTime = DateTime.Now,
                            EditDateTime = DateTime.Now,
                            Maker = User.Identity.GetUserName(),
                            Cheker = "",
                            Status = MyEnums.StatusOptions.Added,
                            UserType = model.UserType
                        };
                       await _userManager.CreateAsync(user, model.Password);
                        if (model.UserType ==MyEnums.UserType.TerminalAdmin)
                        {
                            await _userManager.AddToRoleAsync(user.Id, "TerminalAdmin");
                        }
                        else
                        {
                           await  _userManager.AddToRoleAsync(user.Id, "TerminalOperations");
                        }
                        _logs.LogAudit(User.Identity.GetUserName(), "TerminalUsersRegister", Request.UserHostName,
                               "Added Terminal User :"******"ISA"); 
                    }
                    else
                    {
                        ModelState.AddModelError("", "User Or Email ALready Exists!");
                    }

                }
                return RedirectToAction("TerminalUsersIndex", "Account");
            }
            catch (Exception ex)
            {
                _logs.LogError(User.Identity.GetUserName(), "TerminalUsersRegister", "Error: " + ex.Message,
                    Request.ServerVariables["REMOTE_ADDR"]);
                return HttpNotFound();
            }


        }
Esempio n. 3
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser() { UserName = model.UserName };
                var result = await _userManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInAsync(user, isPersistent: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Esempio n. 4
0
        public async Task<ActionResult> Register(RegisterViewModel model, FormCollection formCollection)
        {
            try
            {
                var roleValue1 = formCollection["CurrentAvailableList"].Split(',');
                if (roleValue1.Length > 0)
                {
                    if (
                        !_dbManager.Users.Any(
                            p => p.UserName == model.UserName.ToLower() && p.Email == model.Email.ToLower()))
                    {
                        var user = new ApplicationUser
                        {
                            UserName = model.UserName.ToLower(),
                            LastLogin = DateTime.Now,
                            Deactivated = false,
                            Enabled = false,
                            Email = model.Email.ToLower(),
                            FirstName = model.Firstname,
                            LastName = model.Lastname,
                            PhoneNumber = model.PhoneNumber,
                            AlternateNumber = model.AlternateNumber,
                            IdentificationNumber = model.IdentificationNumber,
                            OsysDateTime = DateTime.Now,
                            EditDateTime = DateTime.Now,
                            Maker = User.Identity.GetUserName(),
                            Cheker = "",
                            Status = MyEnums.StatusOptions.Added,
                            UserType = MyEnums.UserType.Admin
                        };
                       // _userManager.Create(user, user.UserName.ToLower() + "1234");
                        await _userManager.CreateAsync(user, user.UserName.ToLower() + "1234");

                        foreach (var n in roleValue1)
                        {
                            _userManager.AddToRole(user.Id, n);
                        }
                        _logs.LogAudit(User.Identity.GetUserName(), "Register", Request.UserHostName,
                            "Added User :"******": With Roles:" + formCollection["CurrentAvailableList"].Split(','), "ISA"); 
                    }
                    else
                    {
                        ModelState.AddModelError("", "User Or Email ALready Exists!");
                    }
                    
                }
                return RedirectToAction("RegisterIndex", "Account");
            }
            catch (Exception ex)
            {
                _logs.LogError(User.Identity.GetUserName(), "Register", "Error: " + ex.Message,
                    Request.ServerVariables["REMOTE_ADDR"]);
                return HttpNotFound();
            }

           
        }