protected override Account DoCreateAccount(WebContext context) { Account account = Account.LoadById(int.Parse(context.httprequest.Form["accountId"])); if (!account.needsMigration) { throw new FLocalException("Account '" + account.name + "' is already migrated"); } string userInfo = ShallerGateway.getUserInfoAsString(account.user.name); Regex regex = new Regex("\\(fhn\\:([a-z0-9]+)\\)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline); Match match = regex.Match(userInfo); if (!match.Success) { throw new FLocalException("key (fhn:***) not found on user info page ( http://forumlocal.ru/showprofile.php?User="******"&What=login&showlite=l )"); } string check = Util.md5(match.Groups[1].Value + " " + Config.instance.SaltMigration + " " + account.id); if (check != context.httprequest["check"]) { throw new FLocalException("Wrong key (fhn:" + match.Groups[1].Value + ")"); } if (context.httprequest.Form["password"] != context.httprequest.Form["password2"]) { throw new FLocalException("Passwords mismatch"); } account.migrate(context.httprequest.Form["password"], context.httprequest.UserHostAddress, context.httprequest.Form["registrationEmail"]); return(account); }
public static void ImportUsers(int startFromPage) { for (int i = startFromPage; i < 1000; i++) { System.Console.Write("[" + i + "]"); foreach (string userName in ShallerGateway.getUserNames(i)) { User user; try { User.LoadByName(userName); System.Console.Write("-"); } catch (NotFoundInDBException) { Dictionary <string, string> userData = ShallerGateway.getUserInfo(userName); AbstractChange addUser = new InsertChange( User.TableSpec.instance, new Dictionary <string, AbstractFieldValue> { { User.TableSpec.FIELD_NAME, new ScalarFieldValue(userName) }, { User.TableSpec.FIELD_REGDATE, new ScalarFieldValue(DateTime.Parse(userData["regDate"]).ToUTCString()) }, { User.TableSpec.FIELD_LOCATION, new ScalarFieldValue(userData["location"]) }, { User.TableSpec.FIELD_SHOWPOSTSTOUSERS, new ScalarFieldValue("All") }, { User.TableSpec.FIELD_SIGNATURE, new ScalarFieldValue(userData["signature"]) }, { User.TableSpec.FIELD_SIGNATUREUBB, new ScalarFieldValue(userData["signature"]) }, { User.TableSpec.FIELD_TITLE, new ScalarFieldValue(userData["title"]) }, { User.TableSpec.FIELD_TOTALPOSTS, new ScalarFieldValue("0") }, { User.TableSpec.FIELD_USERGROUPID, new ScalarFieldValue("1") }, { User.TableSpec.FIELD_BIOGRAPHY, new ScalarFieldValue(userData["biography"]) }, { User.TableSpec.FIELD_BIOGRAPHYUBB, new ScalarFieldValue(userData["biography"]) }, } ); AbstractChange addAccount = new InsertChange( Account.TableSpec.instance, new Dictionary <string, AbstractFieldValue> { { Account.TableSpec.FIELD_NAME, new ScalarFieldValue(userName.ToLower()) }, { Account.TableSpec.FIELD_NEEDSMIGRATION, new ScalarFieldValue("1") }, { Account.TableSpec.FIELD_PASSWORDHASH, new ScalarFieldValue("*") }, { Account.TableSpec.FIELD_IPADDRESS, new ScalarFieldValue("127.0.0.1") }, { Account.TableSpec.FIELD_ISSTATUSHIDDEN, new ScalarFieldValue("0") }, { Account.TableSpec.FIELD_ISDETAILEDSTATUSHIDDEN, new ScalarFieldValue("0") }, { Account.TableSpec.FIELD_REGISTRATIONEMAIL, new ScalarFieldValue("[email protected]") }, { Account.TableSpec.FIELD_USERID, new ReferenceFieldValue(addUser) }, } ); AbstractChange addIndicator = new InsertChange( AccountIndicator.TableSpec.instance, new Dictionary <string, AbstractFieldValue> { { AccountIndicator.TableSpec.FIELD_ACCOUNTID, new ReferenceFieldValue(addAccount) }, { AccountIndicator.TableSpec.FIELD_PRIVATEMESSAGES, new ScalarFieldValue("0") }, { AccountIndicator.TableSpec.FIELD_UNREADPRIVATEMESSAGES, new ScalarFieldValue("0") }, } ); ChangeSetUtil.ApplyChanges(addUser, addAccount, addIndicator); user = User.LoadById(addUser.getId().Value); System.Console.Write("."); if (userData["avatar"] != null && userData["avatar"] != "") { Upload avatar; string[] nameParts = userData["avatar"].Split('.'); if (nameParts.Length != 2) { throw new FLocalException("wrong avatar filename '" + userData["avatar"] + "'"); } int oldAvatarId = int.Parse(nameParts[0]); FileInfo avatarInfo = ShallerGateway.getFileInfo("user/" + userData["avatar"]); try { avatar = UploadManager.UploadFile(avatarInfo.dataStream, avatarInfo.fileName, avatarInfo.lastModified, user, 900000 + oldAvatarId); } catch (UploadManager.AlreadyUploadedException e) { avatar = Upload.LoadById(e.uploadId); } ChangeSetUtil.ApplyChanges( new UpdateChange( User.TableSpec.instance, new Dictionary <string, AbstractFieldValue> { { User.TableSpec.FIELD_AVATARID, new ScalarFieldValue(avatar.id.ToString()) } }, user.id ) ); System.Console.Write("a"); } } } } }