Exemplo n.º 1
0
        public IActionResult Login([FromBody] TenantLoginViewModel viewModel)
        {
            var result = _accountService.Login(viewModel);

            if (result.Item1)
            {
                return(Ok(new { Token = result.Item2 }));
            }
            else
            {
                return(this.BadRequestResult(result.Item2));
            }
        }
        public ActionResult CreateLogin()
        {
            var login = new TenantLoginViewModel
            {
                Tenant = new Tenant {
                    Name = "required"
                },
                UserProfile = new UserProfile {
                    Username = "******"
                }
            };

            return(View(login));
        }
        public ActionResult CreateLogin(FormCollection form, TenantLoginViewModel model)
        {
            //todo: implement role for users!  Please design the architecture first!!!
            var tenantDb = new TenantRegistryEntities();
            var tenant   = new Tenant
            {
                id   = System.Guid.NewGuid().ToString(),
                Name = model.Tenant.Name,
                db   = System.Web.Configuration.WebConfigurationManager.AppSettings["NewTenantDatabaseName"],                    // todo: Default Tenant db must be get from a separate class
                ConnectionStringName = System.Web.Configuration.WebConfigurationManager.AppSettings["NewTenantConnectionString"] // todo: Tenant connection string must be get from a separate class
            };

            var userprofile = new UserProfile
            {
                Username  = model.UserProfile.Username,
                FirstName = model.UserProfile.FirstName,
                LastName  = model.UserProfile.LastName
            };


            // Save tenant
            tenant.UserProfiles.Add(userprofile);
            tenantDb.Tenants.AddObject(tenant);
            tenantDb.SaveChanges();


            // Create asp.net login
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                var pw    = form["Password"].ToString();
                var email = form["Email"].ToString();
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserProfile.Username, pw, email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    //FormsService.SignIn(model.UserProfile.Username, false /* createPersistentCookie */);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            return(View("Index"));
        }
Exemplo n.º 4
0
        public (bool, string) Login(TenantLoginViewModel loginViewModel)
        {
            var tenant = _tenantRepository.Get(tenant => tenant.Name == loginViewModel.Account)
                         .FirstOrDefault();

            if (tenant == null)
            {
                return(false, "用户名或密码错误!");
            }
            if (!tenant.IsActive)
            {
                return(false, "该租户未激活!");
            }

            // PostgreSQL版本
            var querySql = @$ "
                SELECT * FROM " "{tenant.Schema}" "." "Member" " WHERE " "{tenant.Schema}" "." "Member" "." "Account" "='{loginViewModel.Account}'";
        public async Task <IActionResult> LoginTenant(TenantLoginViewModel model, string returnUrl = null)
        {
            if (!ModelState.IsValid)
            {
                ViewData["ReturnUrl"] = returnUrl;
                return(View("LoginTenant"));
            }

            var tenantProvider = HttpContext.GetService <TenantProvider>();
            var tenantExists   = await tenantProvider.LookupTenantByDomainAsync(model.TenantDomain);

            if (!tenantExists)
            {
                ModelState.AddModelError("", "We couldn't find your organization.");
                return(Login());
            }

            return(TenantRedirectHelper.RedirectToTenantDomain(model.TenantDomain, "Login", HttpContext.Request, Url));
        }