Example #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);
        }