public override ImportedUser Run(string uname, string pwd) { string uid; var result = new ImportedUser(); string cookie = Login58Vip(uname, pwd, out uid); if (!string.IsNullOrEmpty(cookie)) { string company; List <Wltinfo> wltInfos = GetWltinfoList(cookie, out company); if (wltInfos == null || wltInfos.Count == 0) { //无对应权限 return(null); } ContactInfo info = GetContactInfo(cookie, uid); if (info == null) { return(null); } result.Company = company; result.UserId = uid; result.UserName = info.ContactName; result.Tel = info.PhoneNum; result.Portrait = GetUserIcon(uid); } return(result); }
public override ImportedUser Run(string uname, string pwd) { string cookie = Login(uname, pwd); ImportedUser result = new ImportedUser(); if (cookie == null) { return(null); } string LoginId = Regex.Match(cookie, "LoginId=(\\d+);").Groups[1].Value; var data = new NameValueCollection { { "feeType", "1" }, { "cityScriptIndex", "1001" }, { "pg", "2" }, { "categoryId", "7" }, { "ucUserId", LoginId }, { "pi", "1" }, }; string json = AppPost(basiApi, data, cookie, null, "GetUserPrivilegeByUserId"); try { UserInfo userInfo = JsonConvert.DeserializeObject <UserInfo>(json); string touXiang = userInfo.baseInfo.avatar.Contains("http://") ? userInfo.baseInfo.avatar : (prefixTx + userInfo.baseInfo.avatar); result.Company = userInfo.baseInfo.companyName; result.UserId = LoginId; result.UserName = userInfo.realName; result.Portrait = touXiang; result.Tel = userInfo.phone; return(result); } catch (Exception) { return(null); } }
/// <summary> /// Imports the user table from V2 /// </summary> /// <param name="profileTable">The file w/ user table data</param> /// <param name="delimiter">The delimiter between data</param> /// <param name="work">The DB access</param> private void ImportUsers(HttpPostedFileBase userTable, String delimiter, UnitOfWork work) { // Grab the data List<Dictionary<String, String>> data = GetDataFromFile(userTable, delimiter); if (data == null) { ModelState.AddModelError("", "Error with User table. Check Debug Output"); return; } try { // Disable for speed work.EntityContext.Configuration.AutoDetectChangesEnabled = false; // Go through each data row and create users foreach (Dictionary<String, String> row in data) { String username = row["username"]; String email = row["email"]; // Make the user (don't add directly to DB!) object userObj = new { username = username, first_name = row["real_first_name"], middle_name = row["real_middle_name"], last_name = row["real_last_name"], is_player = Boolean.Parse(row["is_player"]), created_date = DateTime.Parse(row["date_account_created"]), status = Boolean.Parse(row["account_suspended"]) ? (int)JPPConstants.UserStatus.Suspended : (int)JPPConstants.UserStatus.Active, first_login = Boolean.Parse(row["account_first_login"]), email = email, last_login_date = DateTime.Parse(row["date_last_login"]), has_agreed_to_tos = false, // False for everyone! display_name = row["real_first_name"] + " " + row["real_last_name"], privacy_settings = (int)JPPConstants.PrivacySettings.FriendsOnly, communication_settings = (int)JPPConstants.CommunicationSettings.All, notification_settings = 0 }; ImportedUser impUser = new ImportedUser() { Email = email, OldID = int.Parse(row["userID"]), Username = username, UserWasDeleted = false, UsernameConflict = false, EmailConflict = false }; // Check for conflicts impUser.UsernameConflict = work.EntityContext.user.Where(u => u.username == username).Any(); impUser.EmailConflict = work.EntityContext.user.Where(u => u.email == email).Any(); if (!impUser.EmailConflict && !impUser.UsernameConflict) { // No conflicts, so add WebSecurity.CreateUserAndAccount( username, Guid.NewGuid().ToString(), // "Random" password - user will need to reset userObj, false); // No confirmation } // Either way, put in our local map, with the old ID as the key _userMap.Add(impUser.OldID, impUser); } } finally { work.EntityContext.Configuration.AutoDetectChangesEnabled = true; } work.SaveChanges(); // Update all the imported users with new ids foreach (ImportedUser user in _userMap.Values) { // Look up via username int? newID = (from u in work.EntityContext.user where u.username == user.Username select u.id).FirstOrDefault(); if (newID != null && newID.Value != 0) { user.NewID = newID.Value; } else { // Username not found, so try email. If not email, we just can't find the user newID = (from u in work.EntityContext.user where u.email == user.Email select u.id).FirstOrDefault(); if (newID != null && newID.Value != 0) user.NewID = newID.Value; } } }