コード例 #1
0
ファイル: SecurityRepository.cs プロジェクト: Ricium/Wetu
        public User AddUser(User ins)
        {
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            con.Open();

            SqlCommand cmdI = con.CreateCommand();
            SqlTransaction trx = con.BeginTransaction(CommonStrings.InsertTransaction);

            cmdI.Connection = con;
            cmdI.Transaction = trx;

            try
            {
                cmdI.Parameters.Clear();
                cmdI.CommandText = CommonStrings.InsertUser;
                cmdI.CommandType = System.Data.CommandType.StoredProcedure;
                cmdI.Parameters.AddWithValue("@UserId", ins.UserId);
                cmdI.Parameters.AddWithValue("@Username", ins.Username);
                cmdI.Parameters.AddWithValue("@Removed", false);
                cmdI.Parameters.AddWithValue("@CreatedDate", DateTime.Now);
                ins.UserKey = (int)cmdI.ExecuteScalar();

                trx.Commit();
                cmdI.Connection.Close();
            }
            catch (SqlException ex)
            {
                if (trx != null) trx.Rollback();
            }
            finally
            {
                if (con.State != ConnectionState.Closed)
                {
                    con.Close();
                }

                con.Dispose();
                cmdI.Dispose();
                trx.Dispose();
            }

            return ins;
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: Ricium/Wetu
        public ActionResult RegisterUser(RegisterUserModel model, string[] Companies, string[] Permissions)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    Roles.AddUserToRoles(model.UserName, Companies);
                    Roles.AddUserToRoles(model.UserName, Permissions);
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                    User newUser = new User();
                    newUser.Username = model.UserName;
                    newUser.UserId = secRep.GetUserId(model.UserName);
                    newUser = secRep.AddUser(newUser);

                    Account_Rep.SetUserLogin(model.UserName);

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

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #3
0
ファイル: SimulateController.cs プロジェクト: Ricium/Wetu
        public JsonResult AddUserToCompany(string Username, string Password, int CompanyId)
        {
            // Attempt to register the user
            MembershipCreateStatus createStatus;
            Membership.CreateUser(Username, Password, "*****@*****.**", null, null, true, null, out createStatus);

            string CompanyName = secRep.GetCompanyName(CompanyId);

            if (createStatus == MembershipCreateStatus.Success)
            {
                string[] companies = { CompanyName };
                string[] permissions = { "p_admin" };
                Roles.AddUserToRoles(Username, companies);
                Roles.AddUserToRoles(Username, permissions);

                User newUser = new User();
                newUser.Username = Username;
                newUser.UserId = secRep.GetUserId(Username);
                newUser = secRep.AddUser(newUser);

                return Json(newUser.UserKey, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(0, JsonRequestBehavior.AllowGet);
            }
        }
コード例 #4
0
ファイル: SimulateController.cs プロジェクト: Ricium/Wetu
        public ActionResult AddUser(string Username, string Password, string CompanyName)
        {
            // Attempt to register the user
            MembershipCreateStatus createStatus;
            Membership.CreateUser(Username, Password, "*****@*****.**", null, null, true, null, out createStatus);

            if (createStatus == MembershipCreateStatus.Success)
            {
                string[] companies = { "u_" + CompanyName };
                string[] permissions = { "p_admin" };
                Roles.AddUserToRoles(Username, companies);
                Roles.AddUserToRoles(Username, permissions);

                User newUser = new User();
                newUser.Username = Username;
                newUser.UserId = secRep.GetUserId(Username);
                newUser = secRep.AddUser(newUser);

                if (newUser.UserKey == 0)
                {
                    return Content("Fail User", "text/html");
                }
                else
                {
                    return Content("Success User", "text/html");
                }
            }
            else
            {
                return Content("Fail User", "text/html");
            }
        }