Пример #1
0
        public IActionResult GithubCode([FromQuery] string code, [FromQuery] string state)
        {
            try
            {
                _gHAuth.HasState(state);
                string uri = _gHAuth.GetAccessTokenUri(code, state, out KeyValuePair <string, Guid[]> redirect_uri_user_id_pair);
                _gHAuth.RemoveState(state);
                GHAuthenticatedUserInfo user_info = _gHUser.GetAuthenticatedUserInfo(uri);
                Guid   account_id = _account.Add(user_info, VSCID.Github, out bool is_connected);
                string user = "", jwt = "";

                string error = _account.Connect(redirect_uri_user_id_pair.Value[1], account_id);
                if (error != null)
                {
                    if (string.IsNullOrEmpty(redirect_uri_user_id_pair.Key))
                    {
                        return(BadRequest(error));
                    }
                    return(Redirect(redirect_uri_user_id_pair.Key + (redirect_uri_user_id_pair.Key.Contains("?") ? "&" : "?") + "error=" + error));
                }

                user += "nococid";
                jwt  += _jwtAuth.GenerateJwt(redirect_uri_user_id_pair.Value[0], redirect_uri_user_id_pair.Value[1], ApplicationRole.Web_User);
                if (string.IsNullOrEmpty(redirect_uri_user_id_pair.Key))
                {
                    return(Ok(jwt));
                }
                return(Redirect(redirect_uri_user_id_pair.Key + "?user="******"&jwt=" + jwt));
            }
            catch (Exception e)
            {
                return(GetError(e));
            }
        }
Пример #2
0
        public HttpResponseMessage Add([FromBody] AccountViewModel accountView)
        {
            if (accountView == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
            else
            {
                Guid id = Guid.NewGuid();

                Account account = new Account()
                {
                    Id            = id,
                    Email         = accountView.Email,
                    PasswordHash  = accountView.PasswordHash,
                    AccountTypeId = Guid.Parse("5AD9E729-7AE1-479C-9C4A-2ADF46F02256"),
                    isVerified    = accountView.isVerified,
                    CreatedAt     = DateTime.Now,
                    UpdatedAt     = DateTime.Now
                };
                if (service.Add(account) == 1)
                {
                    return(new HttpResponseMessage(HttpStatusCode.OK));
                }
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
        }
Пример #3
0
        public HttpResponseMessage Login(string userName, string passWord)
        {
            var responseMessage = CommonHelper.CreateResponseData(-10005, "用户名或密码错误");

            if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(passWord))
            {
                responseMessage.StatusCode = -10006;
                responseMessage.Message    = "用户名或密码为空";
            }
            else
            {
                var account   = _accountService.LoadEntities(x => x.UserName == userName).SingleOrDefault();
                var isSuccess = _accountService.Add(new Account()
                {
                    UserName = "******", PassWord = "******", CreateTime = DateTime.Now, UpdateTime = DateTime.Now
                });
                if (account != null)
                {
                    if (account.PassWord == passWord.ToMD5Hash())
                    {
                        responseMessage.StatusCode = 1;
                        responseMessage.Message    = "登陆成功";
                    }
                }
            }
            return(responseMessage.ToHttpResponseMessage());
        }
Пример #4
0
        public ActionResult PerformCRUDAction(Account account)
        {
            bool result = false;

            switch (Request.Form["oper"])
            {
            case "add":
                result = _accountService.Add(account);
                break;

            case "edit":
                int id = Int32.Parse(Request.Form["id"]);
                account.Id = id;
                result     = _accountService.Update(account);
                break;

            case "del":
                id         = Int32.Parse(Request.Form["id"]);
                account.Id = id;
                //  result = _accountService.Delete(account);

                break;

            default:
                break;
            }
            return(Json(result));
        }
Пример #5
0
        public IActionResult CreateAdmin(CreateUserViewModel user)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(user));
                }

                _accountService.Add(user);
                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Пример #6
0
        private static void AddAccount(IAccountService accountService)
        {
            Account account = new Account("Mario", 10000);

            Console.WriteLine($"Created account for {account.Owner()}, with balance {account.Balance()}");

            accountService.Add(account);
        }
Пример #7
0
 public ApiResponseViewModel Create(Account obj)
 {
     if (HttpContext.Current.Session["UserLogged"] == null)
     {
         return(CommonConstants.accessDenied);
     }
     return(_accountService.Add(obj));
 }
Пример #8
0
 public IHttpActionResult AddUser([FromBody] OPC_AuthUser user)
 {
     if (_accountService.Add(user))
     {
         return(Ok());
     }
     return(InternalServerError());
 }
Пример #9
0
 public IActionResult Create(Account account)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _accountService.Add(account);
     return(Ok());
 }
        public IActionResult CreateAccount(CreateAccountDto account)
        {
            var result = _accountService.Add(account);

            if (!result.IsError)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Пример #11
0
        public IActionResult Add(Account account)
        {
            var result = _accountService.Add(account);

            if (result.isSuccess)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Пример #12
0
 private void btnCreate_Click(object sender, EventArgs e)
 {
     SetSelectedUserAccountFields();
     try {
         accountService.Add(CurrentAccount);
     } catch (Exception ex) {
         MessageBox.Show("No se ha podido crear la cuenta, error: " + ex.Message);
     }
     RefreshUserAccountsList();
 }
Пример #13
0
        public ActionResult Init()
        {
            _accountService.Add(new Account
            {
                Username = "******",
                Password = "******"
            });

            return(Ok());
        }
Пример #14
0
        public IActionResult Post([FromBody] AccountModel model)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }

            accountService.Add(model);

            return(Ok());
        }
Пример #15
0
 public async Task <ActionResult <Account> > SignUp(AccountRequest account)
 {
     try
     {
         await _accountService.Add(account);
     }
     catch (Exception e)
     {
         return(Content(e.Message));
     }
     return(Content("Success"));
 }
Пример #16
0
 public IActionResult Add([FromBody] AccountViewModelInput accountViewModelInput)
 {
     try
     {
         var account = _accountService.Add(accountViewModelInput);
         return(Created($"/api/v1/accounts/{account?.AccountId}", account));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Пример #17
0
        public async Task <IActionResult> Add([FromBody] Account account)
        {
            ApplicationUser user = await this._userManager.GetUserAsync(HttpContext.User);

            //SignInManager.AuthenticationManager.AuthenticationResponseGrant.Identity.GetUserId();

            //account.UserId = "8d330a12-43ae-4b14-b93b-a2b12cb6feda";
            account.UserId = user.Id;
            account.Id     = Guid.NewGuid();
            accountService.Add(account);
            return(Ok(account));
        }
Пример #18
0
        public ActionResult RegisterUser(UserViewModel model)
        {
            CheckLoginAndEmail(model);

            if (ModelState.IsValid)
            {
                var user = _mapper.Map <UserViewModel, User>(model);

                ((IList <Role>)user.Roles).Add(new Role()
                {
                    RoleEnum = RoleEnum.User
                });
                _accountService.Add(user, CurrentLanguageCode);

                Auth.Login(model.Login, model.Password);

                return(RedirectToAction("GetUsers"));
            }

            return(View(model));
        }
 public ActionResult <Account> Add(Account account)
 {
     try
     {
         _accountService.Add(account);
         _logger.LogInformation($"Created Account with ID {account.Id}");
         return(CreatedAtAction("Add", new { id = account.Id }, account));
     }
     catch
     {
         return(BadRequest());
     }
 }
Пример #20
0
        public bool AddAccount(AccountViewModel viewModel)
        {
            var account = new Account();

            account.Name          = viewModel.Name;
            account.Email         = viewModel.Email;
            account.Url           = viewModel.Url;
            account.Phone         = viewModel.Phone;
            account.AccountType   = (AccountTypeEnum)viewModel.AccountType;
            account.AccountStatus = (AccountStatusEnum)viewModel.AccountStatus;

            return(_accountService.Add(account));
        }
Пример #21
0
        public IActionResult Post([FromBody] TcModel tcModel)
        {
            int    totalCount = accountService.TotalCount();
            string hgsNo      = Convert.ToString(9001.ToString() + totalCount + 1001.ToString());

            Account account = new Account();

            account.Balance = 0.0m;
            account.HgsNo   = hgsNo;
            account.Date    = DateTime.Now;
            account.TcNo    = tcModel.TcNo;

            accountService.Add(account);

            return(Ok(new { status = "success", account.HgsNo, account.Balance, createdDate = account.Date, account.TcNo }));
        }
Пример #22
0
        public async Task <IResultModel> Add(UserAddModel model)
        {
            var entity       = _mapper.Map <UserEntity>(model);
            var maxJobNumber = await _repository.GetMaxJobNumber();

            if (maxJobNumber < 1)
            {
                maxJobNumber = _options.UserInitialJobNumber;
            }

            if (maxJobNumber < 1)
            {
                //д╛хо100000
                maxJobNumber = 100000;
            }

            entity.JobNo = maxJobNumber + 1;

            var account = new AccountAddModel
            {
                Type     = 1,
                UserName = model.UserName,
                Phone    = model.Phone,
                Email    = model.Email,
                Name     = model.Name,
                Roles    = model.Roles,
                Password = model.Password
            };

            _adminUow.BeginTransaction();
            var result = await _accountService.Add(account);

            if (result.Successful)
            {
                entity.AccountId = result.Data;
                _uow.BeginTransaction();
                if (await _repository.AddAsync(entity))
                {
                    _adminUow.Commit();
                    _uow.Commit();
                    return(ResultModel.Success());
                }
            }

            return(result);
        }
        public void AccountService_Create()
        {
            RTC_Account account = new RTC_Account();

            account.Email       = "testService";
            account.Password    = "******";
            account.AccountType = 1;
            account.Status      = true;
            account.UserID      = 1;

            mockRepository.Setup(m => m.Add(account)).Returns((RTC_Account p) =>
            {
                p.AccountID = 1;
                return(p);
            }
                                                              );

            accountService.Add(account);
        }
Пример #24
0
        /// <inheritdoc />
        public Account AddAccount(int customerId, double initialCredit)
        {
            var response = IsValidCustomer(customerId);

            if (response.Equals(Response.Success))
            {
                var account = accountService.Add(customerId);
                if (!initialCredit.NearlyEqual(0))
                {
                    transactionService.Add(account.Id, initialCredit);
                }

                return(accountService.GetById(account.Id));
            }
            else
            {
                throw new MyBankException(response);
            }
        }
Пример #25
0
        public ActionResult Register(AccountRegisterViewModel model)
        {
            ResponseModel response = new ResponseModel();

            if (!ModelState.IsValid)
            {
                response.Success = false;
                response.Msg     = "请认真检查数据是否复合要求,请重新注册";
                return(Json(response));
            }
            if (Session["code"] == null)
            {
                response.Success = false;
                response.Msg     = "验证码已过期,请重新获取验证码";
                return(Json(response));
            }
            if (Session["code"] != null && !Session["code"].ToString().Equals(model.ValidateCode))
            {
                response.Success = false;
                response.Msg     = "验证码输入错误,请重输入验证码";
                return(Json(response));
            }
            #region Register
            Account account = Mapper.Map <Account>(model);
            account.Password = model.Password.ToMd5String();
            account.Sex      = Core.CustomEnum.Sex.Male;
            accountService.Add(account);
            unitOfWork.Commit();
            response.Success = true;
            response.Msg     = "欢迎您的加入!";
            #endregion

            #region Login
            AccountLoginStatusModel loginmodel = new AccountLoginStatusModel();
            loginmodel.ID    = account.Id;
            loginmodel.Name  = account.Name;
            loginmodel.Email = account.Email;
            FormsAuthentication.SetAuthCookie(JsonConvert.SerializeObject(loginmodel), true);
            #endregion
            return(Json(response));
        }
Пример #26
0
        public ActionResult Register(RegistrationViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var user = _accountService.GetByLogin(viewModel.Login);
                if (user == null)
                {
                    var salt = _saltService.Generate();
                    var hash = _saltService.Hash(viewModel.Password, salt);

                    var account = new Entity.Models.Account
                    {
                        FirstName = viewModel.FirstName,
                        LastName  = viewModel.LastName,
                        Age       = viewModel.Age,
                        Gender    = viewModel.Gender,
                        Login     = viewModel.Login,
                        Passport  = viewModel.Passport,
                        Secret    = new Entity.Models.Secret
                        {
                            Hash = hash,
                            Salt = salt
                        }
                    };

                    var created = _accountService.Add(account);
                    if (created != -1)
                    {
                        FormsAuthentication.SetAuthCookie(viewModel.Login, true);
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Пользователь с таким логином уже существует");
            }

            return(View(viewModel));
        }
        public IActionResult CreateAccount([FromBody] AccountCreationRequest account)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                Account domainModel = account.ToDomain();
                domainModel = _accountService.Add(domainModel);
                return(Ok(new AccountCreationResponse(domainModel)));
            }
            catch (InvalidParametersException)
            {
                return(BadRequest("Account properties are not setted corretly."));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #28
0
        private void AddNewAccount()
        {
            Account account = new Account(txtAccountId.Text.ToString());

            account.Username   = txtUsername.Text;
            account.Password   = txtPassword.Text;
            account.FirstName  = txtFirstName.Text.ToString();
            account.LastName   = txtLastName.Text.ToString();;
            account.UserTypeID = textBoxUserTypeID.Text;
            account.Salary     = Convert.ToDouble(txtSalary.Text);
            account.JoinDate   = Convert.ToDateTime(monthCalendarJoinDate.SelectionRange.Start.ToShortDateString());


            ServiceFactory  factory        = new ServiceFactory();
            IAccountService accountService = factory.GetAccountServiceInstance();

            if (accountService.Add(account) == 1)
            {
                this.refreshDelegate.Invoke();
                MessageBox.Show("Record Added Successfully!");
                this.Close();
            }
        }
Пример #29
0
        public async Task <IResultModel> Add(EmployeeAddModel model)
        {
            if (model.Password.NotNull() && !model.Password.Equals(model.ConfirmPassword))
            {
                return(ResultModel.Failed("两次输入的密码不同"));
            }

            var entity = _mapper.Map <EmployeeEntity>(model);

            entity.JoinDate = entity.JoinDate.Date;

            var account = new AccountAddModel
            {
                Type     = AccountType.User,//使用User账户类型
                UserName = model.UserName,
                Name     = model.Name,
                Password = model.Password,
                IsLock   = true,
                Roles    = model.Roles,
                Status   = AccountStatus.Active
            };

            var result = await _accountService.Add(account);

            if (result.Successful)
            {
                entity.AccountId = result.Data;
                if (await _repository.AddAsync(entity))
                {
                    await _cacheHandler.RemoveAsync(CacheKeys.EMPLOYEE_TREE);

                    return(ResultModel.Success());
                }
            }

            return(result);
        }
Пример #30
0
        public async Task <IResultModel> Install(SystemInstallModel model)
        {
            await _moduleInfoService.Sync();

            await _permissionService.Sync(model.Permissions);

            var role = new Role
            {
                Name = "系统管理员"
            };

            await _roleRepository.AddAsync(role);

            await _accountService.Add(new AccountAddModel
            {
                UserName = "******",
                Password = "******",
                Name     = "管理员",
                Roles    = new List <Guid> {
                    role.Id
                }
            });

            UpdateConfig(new SystemConfigModel
            {
                Title    = "通用权限管理系统",
                Auditing = false,
                Toolbar  = new SystemToolbar
                {
                    Fullscreen = true,
                    Skin       = true
                }
            });

            return(ResultModel.Success());
        }