PDA

View Full Version : سوال: ایجاد کاربران در برنامه و سطح دسترسی



oliya24
دوشنبه 27 خرداد 1392, 21:56 عصر
سلام دوستان چطور میشه در یک برنامه کاربری را اضافه و یا حذف کرد؟وچگونه میتوان برای این کاربران سطح دسترسی تعریف کرد؟ ممنون میشم راهنمایی بفرمایید

aghayex
دوشنبه 27 خرداد 1392, 22:04 عصر
ببینیم تعریف شما سطح دسترسی چیه ؟
شما می تونید یه جدول در دیتابیس داشته باشید که در اونجا نام کاربری , رمز , و ستون هایی از نوع بیت که برای تعیین سطح دسترسی کاربران هست بسازید مثلا ستون درج , ستون ویرایش , ستون حذف , ستون گزارش گیری و ... و در برنامه جایی داشته باشید برای تعریف کاربران و اطلاعات این جدول رو در اونجا پر کنید .
حالا وقتی که کاربر بخواد بره یک داده ای رو ثبت کنه باید چک کنی که این کاربر حق داره عمل درج رو انجام بده یا نه . بقیه موارد رو هم مثل همین انجام بده

drsina
دوشنبه 27 خرداد 1392, 22:05 عصر
کدش اینجا هست ، ببین به کارت میاد : http://msdn.microsoft.com/en-US/library/jj966334.aspx

oliya24
دوشنبه 27 خرداد 1392, 22:44 عصر
لینک خرابه داداشم ممنون میشم اصلاحش کنید کسی مثال عملی یا اموزشی نداره لاتیم یا فارسی مهم نیست

esafb52
دوشنبه 27 خرداد 1392, 22:49 عصر
لینک خراب نبود دوست عزیز کدش رو برات گذاشتم

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using AddUser.BingAds.CustomerManagement; namespace AddUser { class Program { private static CustomerManagementServiceClient customerService = null; // Specify your credentials. private static string m_password = "<PasswordGoesHere>"; private static string m_userName = "<UsernameGoesHere>"; private static string m_token = "<DeveloperTokenGoesHere>"; // Specify the identifier of the customer to add the user to. private static long m_customerId = <CustomerIdGoesHere>; static void Main(string[] args) { long userId = -1; try { customerService = new CustomerManagementServiceClient("BasicHttpBinding_ICustomerManagementService"); userId = AddUserToCustomer(m_customerId); if (userId > 0) { Console.WriteLine("Added user {0}", userId); } customerService.Close(); } catch (CommunicationException e) { Console.WriteLine(e.Message); if (customerService != null) { customerService.Abort(); } } catch (TimeoutException e) { Console.WriteLine(e.Message); if (customerService != null) { customerService.Abort(); } } catch (Exception e) { Console.WriteLine(e.Message); if (customerService != null) { customerService.Abort(); } } } // Add a user to the specified customer. static private long AddUserToCustomer(long customerId) { AddUserRequest request = new AddUserRequest(); AddUserResponse response = null; User user = null; long[] accountIds = null; user = GetUserData(); accountIds = GetAccountRestrictions(); try { // If you do not specify Role, the default is the // AdvertiserCampaignManager account role. If you do // not specify a list of account identifiers, the user // will have AdvertiserCampaignManager permission to // all accounts that the customer manages. // You can set Role to the SuperAdmin customer role; // however, to limit the user to a subset of the // customers that the reseller manages, // you must call the UpdateUserRoles operation. request.UserName = userName; request.Password = password; request.DeveloperToken = token; request.User = user; request.AccountIds = accountIds; request.Role = UserRole.AdvertiserCampaignManager; request.User.CustomerId = customerId; response = customerService.AddUser(request); } catch (FaultException<AdApiFaultDetail> fault) { Console.WriteLine("AddUser failed with the following errors:"); foreach (AdApiError error in fault.Detail.Errors) { Console.WriteLine("Error code: {1}\nMessage: {0}\nDetail: {2}\n", error.Message, error.Code, error.Detail); } } catch (FaultException<ApiFault> fault) { Console.WriteLine("AddUser failed with the following errors:"); foreach (OperationError error in fault.Detail.OperationErrors) { if (1339 == error.Code) { Console.WriteLine("A user with username {0} already exists.", request.User.UserName); } else { Console.WriteLine("Error code: {1}\nMessage: {0}\nDetails: {2}\n", error.Message, error.Code, error.Details); } } } return (null != response) ? response.Id : -1; } // Get the information of the user to add. static private User GetUserData() { User user = new User(); ContactInfo contact = new ContactInfo(); Address address = new Address(); PersonName name = new PersonName(); address.Line1 = "1234 Washington Place"; address.Line2 = "Suite 1210"; address.City = "Woodinville"; address.StateOrProvince = "WA"; address.PostalCode = "98068"; address.CountryCode = "US"; contact.Address = address; contact.ContactByPhone = true; contact.Phone1 = "(206) 555-0100 ext. 1234"; contact.Email = "kim@alpineskihouse.com"; contact.EmailFormat = EmailFormat.Text; user.ContactInfo = contact; user.CustomerAppScope = ApplicationType.Advertiser; name.FirstName = "Kim"; name.LastName = "Abercrombie"; user.Name = name; user.Password = "<PasswordGoesHere>"; user.SecretQuestion = SecretQuestion.FatherMiddleName; user.SecretAnswer = "Michael"; user.UserName = "kaberc"; return user; } // Get a list of the accounts that the user is restricted to. // If the user has access to all accounts, return null. // This example limits the user to two accounts. static private long[] GetAccountRestrictions() { long[] accountIds = new long[] { <AccountIdGoesHere>, <AccountIdGoesHere> }; return accountIds; } } }