diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 0735b80..1b003ab 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -904 \ No newline at end of file +906 \ No newline at end of file diff --git a/Common/dataobjects/Account.cs b/Common/dataobjects/Account.cs index 10ddaa9..034b61a 100644 --- a/Common/dataobjects/Account.cs +++ b/Common/dataobjects/Account.cs @@ -18,6 +18,7 @@ namespace FLocal.Common.dataobjects { public const string FIELD_PASSWORDHASH = "Password"; public const string FIELD_NEEDSMIGRATION = "NeedsMigration"; public const string FIELD_NAME = "Name"; + public const string FIELD_IPADDRESS = "IpAddress"; public static readonly TableSpec instance = new TableSpec(); public string name { get { return TABLE; } } public string idName { get { return FIELD_ID; } } @@ -158,7 +159,7 @@ namespace FLocal.Common.dataobjects { } } - public static KeyValuePair getNewAccountChanges(string _name, string password) { + public static KeyValuePair getNewAccountChanges(string _name, string password, string ip) { string name = _name.Trim(); checkNewName(name); checkNewPassword(password); @@ -184,6 +185,7 @@ namespace FLocal.Common.dataobjects { { Account.TableSpec.FIELD_NEEDSMIGRATION, new ScalarFieldValue("0") }, { Account.TableSpec.FIELD_PASSWORDHASH, new ScalarFieldValue(hashPassword(password, name.ToLower())) }, { Account.TableSpec.FIELD_USERID, new ReferenceFieldValue(userInsert) }, + { Account.TableSpec.FIELD_IPADDRESS, new ScalarFieldValue(ip) }, } ); var indicatorInsert = new InsertChange( @@ -204,8 +206,9 @@ namespace FLocal.Common.dataobjects { ); } - public void migrate(string newPassword) { + public void migrate(string newPassword, string ip) { checkNewPassword(newPassword); + if(!this.needsMigration) throw new FLocalException("Already migrated"); ChangeSetUtil.ApplyChanges(new AbstractChange[] { new UpdateChange( TableSpec.instance, @@ -218,6 +221,10 @@ namespace FLocal.Common.dataobjects { TableSpec.FIELD_NEEDSMIGRATION, new ScalarFieldValue("0") }, + { + TableSpec.FIELD_IPADDRESS, + new ScalarFieldValue(ip) + }, }, this.id ), diff --git a/Common/dataobjects/Invite.cs b/Common/dataobjects/Invite.cs index ff1b59a..9f941c9 100644 --- a/Common/dataobjects/Invite.cs +++ b/Common/dataobjects/Invite.cs @@ -84,11 +84,11 @@ namespace FLocal.Common.dataobjects { } private object createAccount_locker = new object(); - public Account createAccount(string code, string name, string password) { + public Account createAccount(string code, string name, string password, string ip) { lock(this.createAccount_locker) { if(this.isUsed) throw new FLocalException("Invite is already used"); if(this.code != code) throw new FLocalException("Wrong code"); - var rawChanges = Account.getNewAccountChanges(name, password); + var rawChanges = Account.getNewAccountChanges(name, password, ip); var accountInsert = rawChanges.Key; var changes = new List(rawChanges.Value); changes.Add( diff --git a/IISMainHandler/handlers/request/MigrateAccountHandler.cs b/IISMainHandler/handlers/request/MigrateAccountHandler.cs index d799682..773c042 100644 --- a/IISMainHandler/handlers/request/MigrateAccountHandler.cs +++ b/IISMainHandler/handlers/request/MigrateAccountHandler.cs @@ -23,7 +23,7 @@ namespace FLocal.IISHandler.handlers.request { 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["password2"]); + account.migrate(context.httprequest.Form["password"], context.httprequest.UserHostAddress); return account; } diff --git a/IISMainHandler/handlers/request/RegisterByInviteHandler.cs b/IISMainHandler/handlers/request/RegisterByInviteHandler.cs index 086afe6..24b9b97 100644 --- a/IISMainHandler/handlers/request/RegisterByInviteHandler.cs +++ b/IISMainHandler/handlers/request/RegisterByInviteHandler.cs @@ -17,7 +17,7 @@ namespace FLocal.IISHandler.handlers.request { Invite invite = Invite.LoadById(int.Parse(context.httprequest.Form["inviteId"])); if(invite.isUsed) throw new FLocalException("Invite is already used"); if(context.httprequest.Form["password"] != context.httprequest.Form["password2"]) throw new FLocalException("Passwords mismatch"); - return invite.createAccount(context.httprequest.Form["code"], context.httprequest.Form["login"], context.httprequest.Form["password"]); + return invite.createAccount(context.httprequest.Form["code"], context.httprequest.Form["login"], context.httprequest.Form["password"], context.httprequest.UserHostAddress); } }