public static sdk.Responses.AccountInfo ToInfoModel(this Account entity) { if (entity != null) { sdk.Responses.AccountInfo response = Mapper.Map <Account, sdk.Responses.AccountInfo>(entity); response.admin = entity.IsAdmin(); return(response); } return(null); }
public object Login(AuthLoginInput input) { return(base.ExecuteFunction <object>("Login", delegate() { Account account = this.API.Direct.Accounts.GetForValidPassword(input.user, input.password); if (account == null) { return Http400("Invalid password/user combination"); } sdk.Responses.AccountInfo data = account.ToInfoModel(); FormsAuthentication.SetAuthCookie(account.account_id.ToString(), input.persist); ItemResult <sdk.Responses.AccountInfo> result = new ItemResult <sdk.Responses.AccountInfo>() { item = data, success = true }; return base.Http200(result); })); }
public object Register(RegisterInput input) { return(base.ExecuteFunction <object>("Register", delegate() { // create/retrieve account Account account = this.API.Direct.Accounts.GetByEmail(input.email); if (account == null) { account = new Account() { account_id = Guid.NewGuid(), disabled = false, first_name = input.first_name, last_name = input.last_name, email = input.email, password = input.password, }; account = this.API.Direct.Accounts.Insert(account); } if (account == null) { return Http500("Unable to create accounts at this time. Please try again soon."); } // Standard Login sdk.Responses.AccountInfo data = account.ToInfoModel(); FormsAuthentication.SetAuthCookie(account.account_id.ToString(), false); ItemResult <sdk.Responses.AccountInfo> result = new ItemResult <sdk.Responses.AccountInfo>() { item = data, success = true }; return base.Http200(result); })); }