예제 #1
0
        public async Task <IActionResult> Registration(UserRegistrationVM registrationVM)
        {
            if (db.users.Any(u => u.login == registrationVM.login))
            {
                ModelState.AddModelError(nameof(registrationVM.login), "This login is already in use");
            }

            if (registrationVM.email != null && db.users.Any(u => u.email == registrationVM.email))
            {
                ModelState.AddModelError(nameof(registrationVM.email), "This email is already in use");
            }

            if (registrationVM.password != registrationVM.confirmPassword)
            {
                ModelState.AddModelError(nameof(registrationVM.password), "Passwords are not same");
            }

            if (ModelState.IsValid)
            {
                UserModel user = registrationVM.GetDbModel();
                db.users.Add(user);
                db.SaveChanges();
                await Authenticate(user.login);

                HttpContext.Session.SetString("login", user.login);
                var session = HttpContext.Session.SessionInfo();
                resultBuilder.AddJSFuncModel("updateUserInfo", session);
                resultBuilder.AddJSFuncInline("reloadHubConnection");
                return(Json(resultBuilder.Build()));
            }
            else
            {
                resultBuilder.AddAspView(this, "Registration", registrationVM);
                return(Json(resultBuilder.Build()));
            }
        }
예제 #2
0
        public IActionResult InitializeCommand(string request)
        {
            var cmdResponse = cmdTranslator.ReadCommand(request);

            terminalResultBuilder.AddAjaxFunc(cmdResponse.action, cmdResponse.cmdParams);
            var result = terminalResultBuilder.Build();

            return(Json(result));
        }