Esempio n. 1
0
        public static LoginResponse Login(LoginRequest request)
        {
            request.mobile_number = Common.GetStandardMobileNumber(request.mobile_number);
            LoginResponse response     = new LoginResponse();
            AgentAdmin    admin        = null;
            string        hashPassword = TokenGenerator.GetHashedPassword(request.password, 49);

            try
            {
                using (AgentAdminDao dao = new AgentAdminDao())
                {
                    admin = dao.FindByMobileNumber(request.mobile_number);
                    if (admin == null)
                    {
                        MakeNouserResponse(response);
                        return(response);
                    }
                    if (hashPassword == admin.Password)
                    {
                        response.code         = 1;
                        response.has_resource = 0;
                        //admin. = request.app_id;
                        admin.AppToken  = request.push_token;
                        admin.AppID     = request.app_id;
                        admin.LastLogin = DateTime.Now;
                        string authToken = TokenGenerator.GenerateToken(admin.AgentAdminName, admin.Password, request.mobile_number);
                        admin.AccToken = authToken;
                        dao.Update(admin);
                        response.code = 0;
                        UserLoginDto dto = new UserLoginDto();
                        AgentHelper.CopyFromEntity(dto, admin);
                        response.user_login   = dto;
                        response.has_resource = 1;
                        response.code         = 0;
                        response.message      = MessagesSource.GetMessage("login.ok");
                        return(response);
                    }
                    else
                    {
                        response.code         = 1;
                        response.has_resource = 0;
                        response.message      = MessagesSource.GetMessage("login.fail");
                    }
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }
            return(response);
        }
Esempio n. 2
0
        public LoginResponse Login(LoginRequest request)
        {
            request.mobile_number = Common.GetStandardMobileNumber(request.mobile_number);
            LoginResponse response     = new LoginResponse();
            Driver        driver       = null;
            string        hashPassword = TokenGenerator.GetHashedPassword(request.password, 49);

            try
            {
                using (DriverDao dao = new DriverDao())
                {
                    //driver = dao.FindByMobileNumber(request.mobile_number);
                    driver = dao.FindByMobileNumberAndPassword(request.mobile_number, hashPassword);

                    if (driver == null)
                    {
                        MakeNoDriverResponse(response);
                        return(response);
                    }

                    driver.AppID     = request.app_id;
                    driver.AppToken  = request.push_token;
                    driver.LastLogin = DateTime.Now;
                    driver.AccToken  = TokenGenerator.GenerateToken(driver.DriverName, driver.Password, driver.MobileNumber);
                    dao.Update(driver);
                    response.code             = 0;
                    response.user_login       = new UserLoginDto();
                    response.driver_details   = new DriverDetails();
                    response.reminder_details = new ReminderDetailsDto();

                    var reminder = dao.GetRemindersForDriver();
                    response.has_reminder = (reminder == null ? 0 : 1);
                    //if (reminder == null)
                    //{
                    //    reminder = new Reminder();
                    //}
                    DriverHelper.CopyFromEntity(response, driver, reminder);

                    response.has_resource = 1;
                    response.message      = MessagesSource.GetMessage("login.ok");
                    return(response);
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }

            return(response);
        }
Esempio n. 3
0
        /// <summary>
        /// Register a new consumer.
        /// </summary>
        /// <param name="request">The DTO with requst form data parameters.</param>
        /// <returns>The response DTO with result of the operation.</returns>
        public RegisterResponse Register(RegisterRequest request)
        {
            request.mobile_number = Common.GetStandardMobileNumber(request.mobile_number);
            RegisterResponse responseDto = new RegisterResponse();
            Consumer         consumer    = new Consumer();

            //Get posted parameter values into the entity from the DTO
            UsersHelper.CopyToEntity(consumer, request);
            consumer.Password = TokenGenerator.GetHashedPassword(request.user_password, 49);//To fit into the password field of database table

            //Generate unique auth /access token for the user.
            consumer.AccToken      = TokenGenerator.GenerateToken(request.user_name, request.user_password, request.mobile_number);
            consumer.CreatedDate   = DateTime.Now;
            consumer.UpdatedDate   = consumer.CreatedDate;
            consumer.StatusID      = 1;
            consumer.ConsActivated = true;
            try
            {
                using (UserDao dao = new UserDao())
                {
                    // Check if the mobile number is registered
                    if (dao.CheckPhoneExists(request.mobile_number))
                    {
                        responseDto.code         = 1;
                        responseDto.has_resource = 0;
                        responseDto.message      = MessagesSource.GetMessage("cons.reg.dupl");
                    }
                    else
                    {
                        consumer = dao.Insert(consumer);                   // save the entity.
                        UsersHelper.CopyFromEntity(responseDto, consumer); //Copy to the response DTO
                        string otp = OTPServices.GenerateAndSendOTP(request.mobile_number);
                        if (OTPServices.SaveOTP(otp, consumer.ConsID, "C"))
                        {
                            responseDto.new_user.send_otp = 1; // state that OTP has been sent.
                        }
                        responseDto.code         = 0;          // Result OK.
                        responseDto.has_resource = 1;
                        responseDto.message      = MessagesSource.GetMessage("cons.reg.ok");
                    }
                }
            }
            catch (Exception ex)
            {
                responseDto.MakeExceptionResponse(ex);
            }
            return(responseDto);
        }
Esempio n. 4
0
        //public static ResendOtpResponse ResendOtp(ResendOtpRequest request)
        //{
        //    ResendOtpResponse response = new ResendOtpResponse();
        //    response.otp_details = new OtpDetailsDto();
        //    AgentBoss agentBoss = null;
        //    try
        //    {
        //        using (AgentBossDao userDao = new AgentBossDao())
        //        {
        //            // agentBoss = GetAuthAgentBoss(request.user_id, request.auth_token, response);
        //            agentBoss = userDao.FindByMobileNumber(request.mobile_number);
        //        }
        //        if (agentBoss == null)
        //        {
        //            MakeNouserResponse(response);
        //            return response;
        //        }

        //        OTPServices.ResendOTP(agentBoss.AbosID, agentBoss.MobileNumber, "B");
        //        response.code = 0;
        //        response.has_resource = 1;
        //        response.message = MessagesSource.GetMessage("otp.resent");
        //        response.otp_details.send_otp = 1;
        //        return response;
        //    }
        //    catch (Exception ex)
        //    {
        //        response.MakeExceptionResponse(ex);
        //        return response;
        //    }
        //}

        public static ResponseDto ResetPassword(ResetPasswordRequest request)
        {
            request.mobile_number = Common.GetStandardMobileNumber(request.mobile_number);
            ResponseDto response            = new ResponseDto();
            AgentBoss   agentBoss           = null;
            string      newPasswordHash     = TokenGenerator.GetHashedPassword(request.new_password, 49);
            string      confirmPasswordHash = TokenGenerator.GetHashedPassword(request.confirm_password, 49);

            try
            {
                //if (!AgentBossServices.CheckAgentBoss(request.user_id, request.auth_token, response))
                //if (!AgentBossServices.CheckAgentBossNotAuthToken(request.user_id, response))
                //{
                //    return response;
                //}
                using (AgentBossDao dao = new AgentBossDao())
                {
                    agentBoss = dao.FindByMobileNumber(request.mobile_number);
                    //agentBoss = dao.FindById(request.user_id);
                    if (agentBoss == null)
                    {
                        MakeNouserResponse(response);
                        return(response);
                    }
                    if (newPasswordHash == confirmPasswordHash)
                    {
                        agentBoss.Password = TokenGenerator.GetHashedPassword(request.new_password, 49);
                        dao.Update(agentBoss);
                        response.code         = 0;
                        response.has_resource = 1;
                        response.message      = MessagesSource.GetMessage("passwd.reset");
                        return(response);
                    }
                }
                response.code         = 1;
                response.has_resource = 0;
                response.message      = MessagesSource.GetMessage("exception");
                return(response);
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }
Esempio n. 5
0
        public static ResponseDto ResetPassword(ResetPasswordRequest request)
        {
            request.mobile_number = Common.GetStandardMobileNumber(request.mobile_number);
            ResponseDto response            = new ResponseDto();
            AgentAdmin  agentAdmin          = null;
            string      newPasswordHash     = TokenGenerator.GetHashedPassword(request.new_password, 49);
            string      confirmPasswordHash = TokenGenerator.GetHashedPassword(request.confirm_password, 49);

            try
            {
                using (AgentAdminDao dao = new AgentAdminDao())
                {
                    agentAdmin = dao.FindByMobileNumber(request.mobile_number);
                    if (agentAdmin == null)
                    {
                        MakeNouserResponse(response);
                        return(response);
                    }
                    if (newPasswordHash == confirmPasswordHash)
                    {
                        agentAdmin.Password = TokenGenerator.GetHashedPassword(request.new_password, 49);
                        dao.Update(agentAdmin);
                        response.code         = 0;
                        response.has_resource = 1;
                        response.message      = MessagesSource.GetMessage("passwd.reset");
                        return(response);
                    }
                }
                response.code         = 1;
                response.has_resource = 0;
                response.message      = MessagesSource.GetMessage("exception");
                return(response);
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }
Esempio n. 6
0
        //public static ResendOtpResponse ResendOtp(ResendOtpRequest request)
        //{
        //    ResendOtpResponse response = new ResendOtpResponse();
        //    response.otp_details = new OtpDetailsDto();
        //    SuperAdmin superuser = null;
        //    try
        //    {
        //        if (!SuperUserServices.CheckSuperUser(request.mobile_number))
        //        {
        //            response.message = MessagesSource.GetMessage("no.super.user");
        //            return response;
        //        }
        //        using (SuperUserDao userDao = new SuperUserDao())
        //        {

        //            superuser = userDao.FindByMobileNumber(request.mobile_number);
        //        }
        //        OTPServices.ResendOTP(superuser.SAdminID, request.mobile_number, "A");
        //        response.code = 0;
        //        response.has_resource = 1;
        //        response.message = MessagesSource.GetMessage("otp.resent");
        //        response.otp_details.send_otp = 1;
        //        return response;
        //    }
        //    catch (Exception ex)
        //    {
        //        response.MakeExceptionResponse(ex);
        //        return response;
        //    }
        //}
        public static ResponseDto ResetPassword(ResetPasswordRequest request)
        {
            ResponseDto response            = new ResponseDto();
            SuperAdmin  superuser           = null;
            string      newPasswordHash     = TokenGenerator.GetHashedPassword(request.new_password, 49);
            string      confirmPasswordHash = TokenGenerator.GetHashedPassword(request.confirm_password, 49);

            try
            {
                if (!SuperUserServices.CheckSuperUser(request.mobile_number))
                {
                    response.message = MessagesSource.GetMessage("no.super.user");
                    return(response);
                }
                using (SuperUserDao dao = new SuperUserDao())
                {
                    superuser = dao.FindByMobileNumber(request.mobile_number);
                    //agentBoss = dao.FindById(request.user_id);
                    if (newPasswordHash == confirmPasswordHash)
                    {
                        superuser.Password = TokenGenerator.GetHashedPassword(request.new_password, 49);
                        dao.Update(superuser);
                        response.code         = 0;
                        response.has_resource = 0;
                        response.message      = MessagesSource.GetMessage("passwd.reset");
                        return(response);
                    }
                }
                response.code         = 1;
                response.has_resource = 0;
                response.message      = MessagesSource.GetMessage("exception");
                return(response);
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }
Esempio n. 7
0
        //public ResendOtpResponse ResendOtp(ResendOtpRequest request)
        //{
        //    ResendOtpResponse response = new ResendOtpResponse();
        //    response.otp_details = new OtpDetailsDto();
        //    Driver driver = null;
        //    try
        //    {
        //        using (DriverDao userDao = new DriverDao())
        //        {
        //            driver = userDao.FindByMobileNumber(request.mobile_number);
        //        }
        //        if (driver == null)
        //        {
        //            MakeNoDriverResponse(response);
        //            return response;
        //        }

        //        OTPServices.ResendOTP(driver.DrvrID, driver.MobileNumber, "D");
        //        response.code = 0;
        //        response.has_resource = 1;
        //        response.message = MessagesSource.GetMessage("otp.resent");
        //        response.otp_details.send_otp = 1;
        //        return response;
        //    }
        //    catch (Exception ex)
        //    {
        //        response.MakeExceptionResponse(ex);
        //        return response;
        //    }
        //}

        public ResponseDto ResetPassword(ResetPasswordRequest request)
        {
            ResponseDto response            = new ResponseDto();
            Driver      driver              = null;
            string      newPasswordHash     = TokenGenerator.GetHashedPassword(request.new_password, 49);
            string      confirmPasswordHash = TokenGenerator.GetHashedPassword(request.confirm_password, 49);

            try
            {
                using (DriverDao dao = new DriverDao())
                {
                    driver = dao.FindByMobileNumber(request.mobile_number);
                    if (driver == null)
                    {
                        MakeNoDriverResponse(response);
                        return(response);
                    }
                    if (newPasswordHash == confirmPasswordHash)
                    {
                        driver.Password = TokenGenerator.GetHashedPassword(request.new_password, 49);
                        dao.Update(driver);
                        response.code         = 0;
                        response.has_resource = 1;
                        response.message      = MessagesSource.GetMessage("passwd.reset");
                        return(response);
                    }
                }
                response.code         = 1;
                response.has_resource = 0;
                response.message      = MessagesSource.GetMessage("exception");
                return(response);
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }
Esempio n. 8
0
        //public static ForgotPasswordResponse ForgotPassword(ForgotPasswordRequest request)
        //{
        //    ForgotPasswordResponse response = new ForgotPasswordResponse();
        //    string newPassword = "******"; //TODO change to generation
        //                                 //TokenGenerator.GenerateResetPassword();
        //    SuperAdmin superuser = null;
        //    try
        //    {
        //        using (SuperUserDao dao = new SuperUserDao())
        //        {
        //            superuser = dao.FindByMobileNumber(request.mobile_number);
        //            if (superuser == null)
        //            {
        //                MakeNouserResponse(response);
        //                return response;
        //            }
        //            superuser.Password = TokenGenerator.GetHashedPassword(newPassword, 49);
        //            dao.Update(superuser);
        //            OTPServices.SendPasswordMessage(superuser.MobileNum, newPassword);
        //            response.code = 0;
        //            response.has_resource = 1;
        //            response.reset_password = new ResetPasswordDto();
        //            response.reset_password.password_otp_sent = 1;
        //            response.reset_password.password_reset = 1;
        //            response.message = MessagesSource.GetMessage("passwd.reset");
        //            return response;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        response.MakeExceptionResponse(ex);
        //        return response;
        //    }
        //}

        public static ResponseDto ChangePassword(ChangePasswordSuperUserRequest request)
        {
            ResponseDto response        = new ResponseDto();
            SuperAdmin  superuser       = null;
            string      oldPasswordHash = TokenGenerator.GetHashedPassword(request.old_password, 49);

            try
            {
                if (!SuperUserServices.CheckSuperUser(request.user_id, request.auth_token, response))
                {
                    response.message = MessagesSource.GetMessage("no.super.user");
                    return(response);
                }
                using (SuperUserDao dao = new SuperUserDao())
                {
                    superuser = dao.FindById(request.user_id);
                    if (superuser.Password == oldPasswordHash)
                    {
                        superuser.Password = TokenGenerator.GetHashedPassword(request.new_password, 49);
                        dao.Update(superuser);
                        response.code         = 0;
                        response.has_resource = 0;
                        response.message      = MessagesSource.GetMessage("password.changed");
                        return(response);
                    }
                }
                response.code         = 1;
                response.has_resource = 0;
                response.message      = MessagesSource.GetMessage("exception");
                return(response);
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }
Esempio n. 9
0
        public static ResponseDto ChangePassword(ChangePasswordAgentBossRequest request)
        {
            ResponseDto response        = new ResponseDto();
            AgentBoss   agentBoss       = null;
            string      oldPasswordHash = TokenGenerator.GetHashedPassword(request.old_password, 49);

            try
            {
                if (!AgentBossServices.CheckAgentBoss(request.user_id, request.auth_token, response))
                {
                    MakeNouserResponse(response);
                    return(response);
                }
                using (AgentBossDao dao = new AgentBossDao())
                {
                    agentBoss = dao.FindById(request.user_id);
                    if (agentBoss.Password == oldPasswordHash)
                    {
                        agentBoss.Password = TokenGenerator.GetHashedPassword(request.new_password, 49);
                        dao.Update(agentBoss);
                        response.code         = 0;
                        response.has_resource = 1;
                        response.message      = MessagesSource.GetMessage("password.changed");
                        return(response);
                    }
                }
                response.code         = 1;
                response.has_resource = 0;
                response.message      = MessagesSource.GetMessage("exception");
                return(response);
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }
Esempio n. 10
0
        public ResponseDto ChangePassword(ChangePasswordRequest request)
        {
            ResponseDto response        = new ResponseDto();
            Consumer    consumer        = null;
            string      oldPasswordHash = TokenGenerator.GetHashedPassword(request.old_password, 49);

            try
            {
                using (UserDao dao = new UserDao())
                {
                    consumer = GetAuthUser(dao, request.user_id, request.auth_token);
                    if (consumer == null)
                    {
                        MakeNouserResponse(response);
                        return(response);
                    }
                    if (consumer.Password == oldPasswordHash)
                    {
                        consumer.Password = TokenGenerator.GetHashedPassword(request.new_password, 49);
                        dao.Update(consumer);
                        response.code         = 0;
                        response.has_resource = 0;
                        response.message      = MessagesSource.GetMessage("password.changed");
                        return(response);
                    }
                }
                response.code         = 1;
                response.has_resource = 0;
                response.message      = MessagesSource.GetMessage("pass.not.chg");
                return(response);
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }