Ejemplo n.º 1
0
        /* Get User Info for User */
        public async Task<OpObject> GetUserInformationForUser(String UserGuid)
        {
            /* 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.Get(UserGuid);
                }
            }), IsoContext);
        }
Ejemplo n.º 2
0
        /* 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);
        }
Ejemplo n.º 3
0
        /* Delete User */
        public async Task<OpObject> DeleteUser(String SessionId, String eMail, String Password)
        {
            /* Create return object */
            IsolatedContext IsoContext = new IsolatedContext(SessionId);

            /* Execute function */
            return await Execute(new Func<Task>(async () =>
            {
                /* We need user repository for this */
                using (UserRepository UserRepo = new UserRepository())
                {
                    /* Does password and email match? */
                    IsoContext.RetObj = await UserRepo.TestPassword(eMail, Password);

                    /* Sanity */
                    if (IsoContext.RetObj.Code != StatusCode.Ok)
                        return;

                    /* Try to delete */
                    IsoContext.RetObj = await UserRepo.Delete(IsoContext.uGuid);
                }
            }), IsoContext);
        }
Ejemplo n.º 4
0
        /* 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);
        }
Ejemplo n.º 5
0
        /* Confirm User */
        public async Task<OpObject> ConfirmUser(String ConfirmationId)
        {
            /* Create return object */
            IsolatedContext IsoContext = new IsolatedContext();

            /* Execute function */
            return await Execute(new Func<Task>(async () =>
            {
                /* Get user guid */
                String uGuid = "0";
                using (MaintienceRepository MainRepo = new MaintienceRepository())
                {
                    /* Delete */
                    uGuid = await MainRepo.DeleteCode(ConfirmationId);
                }

                /* Sanity */
                if (uGuid == "0")
                {
                    IsoContext.RetObj = new OpObject(StatusCode.InvalidParameters);
                    return;
                }

                /* Access user repo */
                using (UserRepository UserRepo = new UserRepository())
                {
                    /* Confirm the user */
                    IsoContext.RetObj = await UserRepo.Confirm(uGuid);
                }
            }), IsoContext);
        }
Ejemplo n.º 6
0
        /* 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);
        }
Ejemplo n.º 7
0
        /* Change Password */
        public async Task<OpObject> ChangePassword(String SessionId, String OldPassword, String NewPassword)
        {
            /* Create return object */
            IsolatedContext IsoContext = new IsolatedContext(SessionId);

            /* Execute function */
            return await Execute(new Func<Task>(async () =>
            {
                /* We need user repository for this */
                using (UserRepository UserRepo = new UserRepository())
                {
                    /* Does old password match? */
                    IsoContext.RetObj = await UserRepo.EditPassword(IsoContext.uGuid, OldPassword, NewPassword);
                }
            }), IsoContext);
        }