/* Create User */ public async Task<OpObject> CreateUser(CCustomer CustomerInfo) { /* Create return object */ IsolatedContext IsoContext = new IsolatedContext(); /* Execute function */ return await Execute(new Func<Task>(async () => { using (UserRepository UserRepo = new UserRepository()) { /* Done */ IsoContext.RetObj = await UserRepo.Create(CustomerInfo, true); /* Sanity */ if (IsoContext.RetObj.Code != StatusCode.Ok) return; /* Create a confirmation code and send the email * to the given user */ using (MaintienceRepository MainRepo = new MaintienceRepository()) { /* Create a new confcode */ String uId = (String)IsoContext.RetObj.Data; String ConfCode = await MainRepo.CreateCode(CodeType.Confirmation, uId); /* Send a new mail */ IsoContext.RetObj = await MainRepo.InsertMail(new CMail() { MailTo = CustomerInfo.Email, Type = MailType.NoReply, Subject = "NRG Models Confirmation", Body = "", IsHtml = false }); } } }), IsoContext); }
/* Login */ public async Task<OpObject> Login(String eMail, String Password) { /* Create return object */ IsolatedContext IsoContext = new IsolatedContext(); /* Execute function */ return await Execute(new Func<Task>(async () => { using (UserRepository UserRepo = new UserRepository()) { /* Does password and email match? */ IsoContext.RetObj = await UserRepo.TestPassword(eMail, Password); /* Return ConfCode */ using (MaintienceRepository MainRepo = new MaintienceRepository()) { /* Very Sanity */ if (IsoContext.RetObj.Code == StatusCode.UserNotConfirmed) { /* Lookup */ String ConfCode = await MainRepo.GetCode(CodeType.Confirmation, (String)IsoContext.RetObj.Data); /* Sanity */ if (ConfCode == "0") { ConfCode = await MainRepo.CreateCode(CodeType.Confirmation, (String)IsoContext.RetObj.Data); } /* Set */ IsoContext.RetObj.Data = ConfCode; } /* Sanity */ if (IsoContext.RetObj.Code != StatusCode.Ok) return; /* Are we logged in already? */ String SessionId = await MainRepo.HasSession((String)IsoContext.RetObj.Data); if (SessionId != "0") { IsoContext.RetObj = new OpObject(StatusCode.Ok, SessionId); return; } /* No, create a session */ IsoContext.RetObj.Data = await MainRepo.CreateSessionId((String)IsoContext.RetObj.Data); } } }), IsoContext); }
/* Forgot Password */ public async Task<OpObject> ForgotPassword(String eMail) { /* Create return object */ IsolatedContext IsoContext = new IsolatedContext(); /* Execute function */ return await Execute(new Func<Task>(async () => { using (UserRepository UserRepo = new UserRepository()) { /* Done */ IsoContext.RetObj = await UserRepo.GetGuid(eMail); /* Sanity */ if (IsoContext.RetObj.Code != StatusCode.Ok) return; /* Get confirmation code */ using (MaintienceRepository MainRepo = new MaintienceRepository()) { String ConfCode = await MainRepo.CreateCode(CodeType.Recovery, (String)IsoContext.RetObj.Data); /* Save it */ IsoContext.RetObj.Data = ConfCode; } } }), IsoContext); }